3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 """Test service for regression testing of Cloud Endpoints support."""
21 from protorpc
import message_types
22 from protorpc
import messages
23 from protorpc
import remote
25 from google
.appengine
.ext
import endpoints
28 class TestRequest(messages
.Message
):
29 """Simple ProtoRPC request, for testing."""
30 name
= messages
.StringField(1)
31 number
= messages
.IntegerField(2)
34 class TestResponse(messages
.Message
):
35 """Simple ProtoRPC response with a text field."""
36 text
= messages
.StringField(1)
39 class TestDateTime(messages
.Message
):
40 """Simple ProtoRPC request/response with a datetime."""
41 datetime_value
= message_types
.DateTimeField(1)
44 my_api
= endpoints
.api(name
='test_service', version
='v1')
48 class TestService(remote
.Service
):
49 """ProtoRPC test class for Cloud Endpoints."""
51 @endpoints.method(message_types
.VoidMessage
, TestResponse
,
52 http_method
='GET', name
='test', path
='test',
54 def test(self
, unused_request
):
55 return TestResponse(text
='Test response')
57 @endpoints.method(TestRequest
, TestResponse
,
58 http_method
='POST', name
='t2name', path
='t2path',
60 def getenviron(self
, request
):
61 return TestResponse(text
='%s %d' % (request
.name
, request
.number
))
63 @endpoints.method(message_types
.DateTimeMessage
,
64 message_types
.DateTimeMessage
,
65 http_method
='POST', name
='echodtmsg',
66 path
='echo_datetime_message',
68 def echo_datetime_message(self
, request
):
71 @endpoints.method(TestDateTime
, TestDateTime
,
72 http_method
='POST', name
='echodtfield',
73 path
='echo_datetime_field',
75 def echo_datetime_field(self
, request
):
76 # Make sure we can access the fields of the datetime object.
77 logging
.info('Year %d, Month %d', request
.datetime_value
.year
,
78 request
.datetime_value
.month
)
82 @my_api.collection(resource_name
='extraname', path
='extrapath')
83 class ExtraMethods(remote
.Service
):
84 """Some extra test methods in the test API."""
86 @endpoints.method(message_types
.VoidMessage
, TestResponse
,
87 http_method
='GET', name
='test', path
='test',
89 def test(self
, unused_request
):
90 return TestResponse(text
='Extra test response')
93 application
= endpoints
.api_server([TestService
, ExtraMethods
])