Skip to content

Commit 12d32a8

Browse files
committed
Merge branch 'master' into async
2 parents 799481e + 0ec9fe6 commit 12d32a8

File tree

12 files changed

+412
-68
lines changed

12 files changed

+412
-68
lines changed
File renamed without changes.
File renamed without changes.

appengine/endpoints/multiapi/app.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
runtime: python27
2+
threadsafe: true
3+
api_version: 1
4+
5+
handlers:
6+
# The endpoints handler must be mapped to /_ah/spi.
7+
# Apps send requests to /_ah/api, but the endpoints service handles mapping
8+
# those requests to /_ah/spi.
9+
- url: /_ah/spi/.*
10+
script: main.api
11+
12+
libraries:
13+
- name: pycrypto
14+
version: 2.6
15+
- name: endpoints
16+
version: 1.0

appengine/endpoints/multiapi/main.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""This is a sample multi-class API implemented using Cloud Ednpoints"""
16+
17+
import endpoints
18+
from protorpc import messages
19+
from protorpc import remote
20+
21+
22+
class Request(messages.Message):
23+
message = messages.StringField(1)
24+
25+
26+
class Response(messages.Message):
27+
message = messages.StringField(1)
28+
29+
30+
# [START multiclass]
31+
api_collection = endpoints.api(name='library', version='v1.0')
32+
33+
34+
@api_collection.api_class(resource_name='shelves')
35+
class Shelves(remote.Service):
36+
37+
@endpoints.method(Request, Response, path='list')
38+
def list(self, request):
39+
return Response()
40+
41+
42+
# [START books]
43+
@api_collection.api_class(resource_name='books', path='books')
44+
class Books(remote.Service):
45+
46+
@endpoints.method(Request, Response, path='bookmark')
47+
def bookmark(self, request):
48+
return Response()
49+
# [END books]
50+
# [END multiclass]
51+
52+
# [START api_server]
53+
api = endpoints.api_server([api_collection])
54+
# [END api_server]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import main
16+
17+
18+
def test_shelves(testbed):
19+
api = main.Shelves()
20+
response = api.list(main.Request())
21+
assert response
22+
23+
24+
def test_books(testbed):
25+
api = main.Books()
26+
response = api.bookmark(main.Request())
27+
assert response

appengine/ndb/entities/snippets_test.py

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,79 +12,68 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import inspect
16-
1715
from google.appengine.api import users
1816
from google.appengine.ext import ndb
1917
from google.appengine.ext.ndb.google_imports import datastore_errors
2018
import pytest
2119
import snippets
2220

2321

24-
@pytest.yield_fixture
25-
def client(testbed):
26-
yield testbed
27-
28-
for name, obj in inspect.getmembers(snippets):
29-
if inspect.isclass(obj) and issubclass(obj, ndb.Model):
30-
ndb.delete_multi(obj.query().iter(keys_only=True))
31-
32-
33-
def test_create_model_using_keyword_arguments(client):
22+
def test_create_model_using_keyword_arguments(testbed):
3423
result = snippets.create_model_using_keyword_arguments()
3524
assert isinstance(result, snippets.Account)
3625

3726

38-
def test_create_model_using_attributes(client):
27+
def test_create_model_using_attributes(testbed):
3928
result = snippets.create_model_using_attributes()
4029
assert isinstance(result, snippets.Account)
4130

4231

43-
def test_create_model_using_populate(client):
32+
def test_create_model_using_populate(testbed):
4433
result = snippets.create_model_using_populate()
4534
assert isinstance(result, snippets.Account)
4635

4736

48-
def test_demonstrate_model_constructor_type_checking(client):
37+
def test_demonstrate_model_constructor_type_checking(testbed):
4938
with pytest.raises(datastore_errors.BadValueError):
5039
snippets.demonstrate_model_constructor_type_checking()
5140

5241

53-
def test_dmonstrate_model_attribute_type_checking(client):
42+
def test_dmonstrate_model_attribute_type_checking(testbed):
5443
with pytest.raises(datastore_errors.BadValueError):
5544
snippets.dmonstrate_model_attribute_type_checking(
5645
snippets.create_model_using_keyword_arguments())
5746

5847

59-
def test_save_model(client):
48+
def test_save_model(testbed):
6049
result = snippets.save_model(
6150
snippets.create_model_using_keyword_arguments())
6251
assert isinstance(result, snippets.ndb.Key)
6352

6453

65-
def test_get_model(client):
54+
def test_get_model(testbed):
6655
sandy_key = snippets.save_model(
6756
snippets.create_model_using_keyword_arguments())
6857
result = snippets.get_model(sandy_key)
6958
assert isinstance(result, snippets.Account)
7059

7160

72-
def test_get_key_kind_and_id(client):
61+
def test_get_key_kind_and_id(testbed):
7362
sandy_key = snippets.save_model(
7463
snippets.create_model_using_keyword_arguments())
7564
kind_string, ident = snippets.get_key_kind_and_id(sandy_key)
7665
assert kind_string == 'Account'
7766
assert isinstance(ident, long)
7867

7968

80-
def test_get_url_safe_key(client):
69+
def test_get_url_safe_key(testbed):
8170
sandy_key = snippets.save_model(
8271
snippets.create_model_using_keyword_arguments())
8372
result = snippets.get_url_safe_key(sandy_key)
8473
assert isinstance(result, str)
8574

8675

87-
def test_get_model_from_url_safe_key(client):
76+
def test_get_model_from_url_safe_key(testbed):
8877
sandy_key = snippets.save_model(
8978
snippets.create_model_using_keyword_arguments())
9079
result = snippets.get_model_from_url_safe_key(
@@ -93,7 +82,7 @@ def test_get_model_from_url_safe_key(client):
9382
assert result.username == 'Sandy'
9483

9584

96-
def test_get_key_and_numeric_id_from_url_safe_key(client):
85+
def test_get_key_and_numeric_id_from_url_safe_key(testbed):
9786
sandy_key = snippets.save_model(
9887
snippets.create_model_using_keyword_arguments())
9988
urlsafe = snippets.get_url_safe_key(sandy_key)
@@ -104,7 +93,7 @@ def test_get_key_and_numeric_id_from_url_safe_key(client):
10493
assert isinstance(kind_string, str)
10594

10695

107-
def test_update_model_from_key(client):
96+
def test_update_model_from_key(testbed):
10897
sandy = snippets.create_model_using_keyword_arguments()
10998
sandy_key = snippets.save_model(sandy)
11099
urlsafe = snippets.get_url_safe_key(sandy_key)
@@ -114,92 +103,92 @@ def test_update_model_from_key(client):
114103
assert key.get().email == '[email protected]'
115104

116105

117-
def test_delete_model(client):
106+
def test_delete_model(testbed):
118107
sandy = snippets.create_model_using_keyword_arguments()
119108
snippets.save_model(sandy)
120109
snippets.delete_model(sandy)
121110
assert sandy.key.get() is None
122111

123112

124-
def test_create_model_with_named_key(client):
113+
def test_create_model_with_named_key(testbed):
125114
result = snippets.create_model_with_named_key()
126115
assert '[email protected]' == result
127116

128117

129-
def test_set_key_directly(client):
118+
def test_set_key_directly(testbed):
130119
account = snippets.Account()
131120
snippets.set_key_directly(account)
132121
assert account.key.id() == '[email protected]'
133122

134123

135-
def test_create_model_with_generated_id(client):
124+
def test_create_model_with_generated_id(testbed):
136125
result = snippets.create_model_with_generated_id()
137126
assert isinstance(result.key.id(), long)
138127

139128

140-
def test_demonstrate_models_with_parent_hierarchy(client):
129+
def test_demonstrate_models_with_parent_hierarchy(testbed):
141130
snippets.demonstrate_models_with_parent_hierarchy()
142131

143132

144-
def test_equivalent_ways_to_define_key_with_parent(client):
133+
def test_equivalent_ways_to_define_key_with_parent(testbed):
145134
snippets.equivalent_ways_to_define_key_with_parent()
146135

147136

148-
def test_create_root_key(client):
137+
def test_create_root_key(testbed):
149138
result = snippets.create_root_key()
150139
assert result.id() == '[email protected]'
151140

152141

153-
def test_create_model_with_parent_keys(client):
142+
def test_create_model_with_parent_keys(testbed):
154143
result = snippets.create_model_with_parent_keys()
155144
assert result.message_text == 'Hello'
156145

157146

158-
def test_get_parent_key_of_model(client):
147+
def test_get_parent_key_of_model(testbed):
159148
initial_revision = snippets.create_model_with_parent_keys()
160149
result = snippets.get_parent_key_of_model(initial_revision)
161150
assert result.kind() == 'Message'
162151

163152

164-
def test_operate_on_multiple_keys_at_once(client):
153+
def test_operate_on_multiple_keys_at_once(testbed):
165154
snippets.operate_on_multiple_keys_at_once([
166155
snippets.Account(email='[email protected]'), snippets.Account(email='[email protected]')])
167156

168157

169-
def test_create_expando_model(client):
158+
def test_create_expando_model(testbed):
170159
result = snippets.create_expando_model()
171160
assert result.foo == 1
172161

173162

174-
def test_get_properties_defined_on_expando(client):
163+
def test_get_properties_defined_on_expando(testbed):
175164
result = snippets.get_properties_defined_on_expando(
176165
snippets.create_expando_model())
177166
assert result['foo'] is not None
178167
assert result['bar'] is not None
179168
assert result['tags'] is not None
180169

181170

182-
def test_create_expando_model_with_defined_properties(client):
171+
def test_create_expando_model_with_defined_properties(testbed):
183172
result = snippets.create_expando_model_with_defined_properties()
184173
assert result.name == 'Sandy'
185174

186175

187-
def test_create_expando_model_that_isnt_indexed_by_default(client):
176+
def test_create_expando_model_that_isnt_indexed_by_default(testbed):
188177
result = snippets.create_expando_model_that_isnt_indexed_by_default()
189178
assert result['foo']
190179
assert result['bar']
191180

192181

193-
def test_demonstrate_wrong_way_to_query_expando(client):
182+
def test_demonstrate_wrong_way_to_query_expando(testbed):
194183
with pytest.raises(AttributeError):
195184
snippets.demonstrate_wrong_way_to_query_expando()
196185

197186

198-
def test_demonstrate_right_way_to_query_expando(client):
187+
def test_demonstrate_right_way_to_query_expando(testbed):
199188
snippets.demonstrate_right_way_to_query_expando()
200189

201190

202-
def test_demonstrate_model_put_and_delete_hooks(client):
191+
def test_demonstrate_model_put_and_delete_hooks(testbed):
203192
iterator = snippets.demonstrate_model_put_and_delete_hooks()
204193
iterator.next()
205194
assert snippets.notification == 'Gee wiz I have a new friend!'
@@ -208,29 +197,29 @@ def test_demonstrate_model_put_and_delete_hooks(client):
208197
'I have found occasion to rethink our friendship.')
209198

210199

211-
def test_reserve_model_ids(client):
200+
def test_reserve_model_ids(testbed):
212201
first, last = snippets.reserve_model_ids()
213202
assert last - first >= 99
214203

215204

216-
def test_reserve_model_ids_with_a_parent(client):
205+
def test_reserve_model_ids_with_a_parent(testbed):
217206
first, last = snippets.reserve_model_ids_with_a_parent(
218207
snippets.Friend().key)
219208
assert last - first >= 99
220209

221210

222-
def test_construct_keys_from_range_of_reserved_ids(client):
211+
def test_construct_keys_from_range_of_reserved_ids(testbed):
223212
result = snippets.construct_keys_from_range_of_reserved_ids(
224213
*snippets.reserve_model_ids())
225214
assert len(result) == 100
226215

227216

228-
def test_reserve_model_ids_up_to(client):
217+
def test_reserve_model_ids_up_to(testbed):
229218
first, last = snippets.reserve_model_ids_up_to(5)
230219
assert last - first >= 4
231220

232221

233-
def test_model_with_user(client):
222+
def test_model_with_user(testbed):
234223
user = users.User(email='[email protected]', _user_id='123')
235224
item = snippets.ModelWithUser(user_id=user.user_id())
236225
item.put()

0 commit comments

Comments
 (0)