Skip to content

Commit 9e63c7d

Browse files
committed
Merge pull request #367 from GoogleCloudPlatform/entity_rename
Rename model usage to entity
2 parents 28cd7b0 + f3e079e commit 9e63c7d

File tree

2 files changed

+70
-69
lines changed

2 files changed

+70
-69
lines changed

appengine/standard/ndb/entities/snippets.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ class Account(ndb.Model):
2121
email = ndb.StringProperty()
2222

2323

24-
def create_model_using_keyword_arguments():
24+
def create_entity_using_keyword_arguments():
2525
sandy = Account(
2626
username='Sandy', userid=123, email='[email protected]')
2727
return sandy
2828

2929

30-
def create_model_using_attributes():
30+
def create_entity_using_attributes():
3131
sandy = Account()
3232
sandy.username = 'Sandy'
3333
sandy.userid = 123
3434
sandy.email = '[email protected]'
3535
return sandy
3636

3737

38-
def create_model_using_populate():
38+
def create_entity_using_populate():
3939
sandy = Account()
4040
sandy.populate(
4141
username='Sandy',
@@ -50,16 +50,16 @@ def demonstrate_model_constructor_type_checking():
5050
return bad
5151

5252

53-
def dmonstrate_model_attribute_type_checking(sandy):
53+
def demonstrate_entity_attribute_type_checking(sandy):
5454
sandy.username = 42 # raises an exception
5555

5656

57-
def save_model(sandy):
57+
def save_entity(sandy):
5858
sandy_key = sandy.put()
5959
return sandy_key
6060

6161

62-
def get_model(sandy_key):
62+
def get_entity(sandy_key):
6363
sandy = sandy_key.get()
6464
return sandy
6565

@@ -75,7 +75,7 @@ def get_url_safe_key(sandy_key):
7575
return url_string
7676

7777

78-
def get_model_from_url_safe_key(url_string):
78+
def get_entity_from_url_safe_key(url_string):
7979
sandy_key = ndb.Key(urlsafe=url_string)
8080
sandy = sandy_key.get()
8181
return sandy
@@ -88,17 +88,17 @@ def get_key_and_numeric_id_from_url_safe_key(url_string):
8888
return key, ident, kind_string
8989

9090

91-
def update_model_from_key(key):
91+
def update_entity_from_key(key):
9292
sandy = key.get()
9393
sandy.email = '[email protected]'
9494
sandy.put()
9595

9696

97-
def delete_model(sandy):
97+
def delete_entity(sandy):
9898
sandy.key.delete()
9999

100100

101-
def create_model_with_named_key():
101+
def create_entity_with_named_key():
102102
account = Account(
103103
username='Sandy', userid=1234, email='[email protected]',
104104
@@ -114,7 +114,7 @@ def set_key_directly(account):
114114
account.key = ndb.Key(Account, '[email protected]')
115115

116116

117-
def create_model_with_generated_id():
117+
def create_entity_with_generated_id():
118118
# note: no id kwarg
119119
account = Account(username='Sandy', userid=1234, email='[email protected]')
120120
account.put()
@@ -127,7 +127,7 @@ class Revision(ndb.Model):
127127
message_text = ndb.StringProperty()
128128

129129

130-
def demonstrate_models_with_parent_hierarchy():
130+
def demonstrate_entities_with_parent_hierarchy():
131131
ndb.Key('Account', '[email protected]', 'Message', 123, 'Revision', '1')
132132
ndb.Key('Account', '[email protected]', 'Message', 123, 'Revision', '2')
133133
ndb.Key('Account', '[email protected]', 'Message', 456, 'Revision', '1')
@@ -149,7 +149,7 @@ def create_root_key():
149149
return sandy_key
150150

151151

152-
def create_model_with_parent_keys():
152+
def create_entity_with_parent_keys():
153153
account_key = ndb.Key(Account, '[email protected]')
154154

155155
# Ask Datastore to allocate an ID.
@@ -167,7 +167,7 @@ def create_model_with_parent_keys():
167167
return initial_revision
168168

169169

170-
def get_parent_key_of_model(initial_revision):
170+
def get_parent_key_of_entity(initial_revision):
171171
message_key = initial_revision.key.parent()
172172
return message_key
173173

@@ -182,7 +182,7 @@ class Mine(ndb.Expando):
182182
pass
183183

184184

185-
def create_expando_model():
185+
def create_entity_using_expando_model():
186186
e = Mine()
187187
e.foo = 1
188188
e.bar = 'blah'
@@ -206,7 +206,7 @@ class FlexEmployee(ndb.Expando):
206206
age = ndb.IntegerProperty()
207207

208208

209-
def create_expando_model_with_defined_properties():
209+
def create_expando_model_entity_with_defined_properties():
210210
employee = FlexEmployee(name='Sandy', location='SF')
211211
return employee
212212

@@ -215,7 +215,7 @@ class Specialized(ndb.Expando):
215215
_default_indexed = False
216216

217217

218-
def create_expando_model_that_isnt_indexed_by_default():
218+
def create_expando_model_entity_that_isnt_indexed_by_default():
219219
e = Specialized(foo='a', bar=['b'])
220220
return e._properties
221221
# {

appengine/standard/ndb/entities/snippets_test.py

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
import snippets
2020

2121

22-
def test_create_model_using_keyword_arguments(testbed):
23-
result = snippets.create_model_using_keyword_arguments()
22+
def test_create_entity_using_keyword_arguments(testbed):
23+
result = snippets.create_entity_using_keyword_arguments()
2424
assert isinstance(result, snippets.Account)
2525

2626

27-
def test_create_model_using_attributes(testbed):
28-
result = snippets.create_model_using_attributes()
27+
def test_create_entity_using_attributes(testbed):
28+
result = snippets.create_entity_using_attributes()
2929
assert isinstance(result, snippets.Account)
3030

3131

32-
def test_create_model_using_populate(testbed):
33-
result = snippets.create_model_using_populate()
32+
def test_create_entity_using_populate(testbed):
33+
result = snippets.create_entity_using_populate()
3434
assert isinstance(result, snippets.Account)
3535

3636

@@ -39,52 +39,52 @@ def test_demonstrate_model_constructor_type_checking(testbed):
3939
snippets.demonstrate_model_constructor_type_checking()
4040

4141

42-
def test_dmonstrate_model_attribute_type_checking(testbed):
42+
def test_demonstrate_entity_attribute_type_checking(testbed):
4343
with pytest.raises(datastore_errors.BadValueError):
44-
snippets.dmonstrate_model_attribute_type_checking(
45-
snippets.create_model_using_keyword_arguments())
44+
snippets.demonstrate_entity_attribute_type_checking(
45+
snippets.create_entity_using_keyword_arguments())
4646

4747

48-
def test_save_model(testbed):
49-
result = snippets.save_model(
50-
snippets.create_model_using_keyword_arguments())
48+
def test_save_entity(testbed):
49+
result = snippets.save_entity(
50+
snippets.create_entity_using_keyword_arguments())
5151
assert isinstance(result, snippets.ndb.Key)
5252

5353

54-
def test_get_model(testbed):
55-
sandy_key = snippets.save_model(
56-
snippets.create_model_using_keyword_arguments())
57-
result = snippets.get_model(sandy_key)
54+
def test_get_entity(testbed):
55+
sandy_key = snippets.save_entity(
56+
snippets.create_entity_using_keyword_arguments())
57+
result = snippets.get_entity(sandy_key)
5858
assert isinstance(result, snippets.Account)
5959

6060

6161
def test_get_key_kind_and_id(testbed):
62-
sandy_key = snippets.save_model(
63-
snippets.create_model_using_keyword_arguments())
62+
sandy_key = snippets.save_entity(
63+
snippets.create_entity_using_keyword_arguments())
6464
kind_string, ident = snippets.get_key_kind_and_id(sandy_key)
6565
assert kind_string == 'Account'
6666
assert isinstance(ident, long)
6767

6868

6969
def test_get_url_safe_key(testbed):
70-
sandy_key = snippets.save_model(
71-
snippets.create_model_using_keyword_arguments())
70+
sandy_key = snippets.save_entity(
71+
snippets.create_entity_using_keyword_arguments())
7272
result = snippets.get_url_safe_key(sandy_key)
7373
assert isinstance(result, str)
7474

7575

76-
def test_get_model_from_url_safe_key(testbed):
77-
sandy_key = snippets.save_model(
78-
snippets.create_model_using_keyword_arguments())
79-
result = snippets.get_model_from_url_safe_key(
76+
def test_get_entity_from_url_safe_key(testbed):
77+
sandy_key = snippets.save_entity(
78+
snippets.create_entity_using_keyword_arguments())
79+
result = snippets.get_entity_from_url_safe_key(
8080
snippets.get_url_safe_key(sandy_key))
8181
assert isinstance(result, snippets.Account)
8282
assert result.username == 'Sandy'
8383

8484

8585
def test_get_key_and_numeric_id_from_url_safe_key(testbed):
86-
sandy_key = snippets.save_model(
87-
snippets.create_model_using_keyword_arguments())
86+
sandy_key = snippets.save_entity(
87+
snippets.create_entity_using_keyword_arguments())
8888
urlsafe = snippets.get_url_safe_key(sandy_key)
8989
key, ident, kind_string = (
9090
snippets.get_key_and_numeric_id_from_url_safe_key(urlsafe))
@@ -93,25 +93,25 @@ def test_get_key_and_numeric_id_from_url_safe_key(testbed):
9393
assert isinstance(kind_string, str)
9494

9595

96-
def test_update_model_from_key(testbed):
97-
sandy = snippets.create_model_using_keyword_arguments()
98-
sandy_key = snippets.save_model(sandy)
96+
def test_update_entity_from_key(testbed):
97+
sandy = snippets.create_entity_using_keyword_arguments()
98+
sandy_key = snippets.save_entity(sandy)
9999
urlsafe = snippets.get_url_safe_key(sandy_key)
100100
key, ident, kind_string = (
101101
snippets.get_key_and_numeric_id_from_url_safe_key(urlsafe))
102-
snippets.update_model_from_key(key)
102+
snippets.update_entity_from_key(key)
103103
assert key.get().email == '[email protected]'
104104

105105

106-
def test_delete_model(testbed):
107-
sandy = snippets.create_model_using_keyword_arguments()
108-
snippets.save_model(sandy)
109-
snippets.delete_model(sandy)
106+
def test_delete_entity(testbed):
107+
sandy = snippets.create_entity_using_keyword_arguments()
108+
snippets.save_entity(sandy)
109+
snippets.delete_entity(sandy)
110110
assert sandy.key.get() is None
111111

112112

113-
def test_create_model_with_named_key(testbed):
114-
result = snippets.create_model_with_named_key()
113+
def test_create_entity_with_named_key(testbed):
114+
result = snippets.create_entity_with_named_key()
115115
assert '[email protected]' == result
116116

117117

@@ -121,13 +121,13 @@ def test_set_key_directly(testbed):
121121
assert account.key.id() == '[email protected]'
122122

123123

124-
def test_create_model_with_generated_id(testbed):
125-
result = snippets.create_model_with_generated_id()
124+
def test_create_entity_with_generated_id(testbed):
125+
result = snippets.create_entity_with_generated_id()
126126
assert isinstance(result.key.id(), long)
127127

128128

129-
def test_demonstrate_models_with_parent_hierarchy(testbed):
130-
snippets.demonstrate_models_with_parent_hierarchy()
129+
def test_demonstrate_entities_with_parent_hierarchy(testbed):
130+
snippets.demonstrate_entities_with_parent_hierarchy()
131131

132132

133133
def test_equivalent_ways_to_define_key_with_parent(testbed):
@@ -139,14 +139,14 @@ def test_create_root_key(testbed):
139139
assert result.id() == '[email protected]'
140140

141141

142-
def test_create_model_with_parent_keys(testbed):
143-
result = snippets.create_model_with_parent_keys()
142+
def test_create_entity_with_parent_keys(testbed):
143+
result = snippets.create_entity_with_parent_keys()
144144
assert result.message_text == 'Hello'
145145

146146

147-
def test_get_parent_key_of_model(testbed):
148-
initial_revision = snippets.create_model_with_parent_keys()
149-
result = snippets.get_parent_key_of_model(initial_revision)
147+
def test_get_parent_key_of_entity(testbed):
148+
initial_revision = snippets.create_entity_with_parent_keys()
149+
result = snippets.get_parent_key_of_entity(initial_revision)
150150
assert result.kind() == 'Message'
151151

152152

@@ -155,26 +155,27 @@ def test_operate_on_multiple_keys_at_once(testbed):
155155
snippets.Account(email='[email protected]'), snippets.Account(email='[email protected]')])
156156

157157

158-
def test_create_expando_model(testbed):
159-
result = snippets.create_expando_model()
158+
def test_create_entity_using_expando_model(testbed):
159+
result = snippets.create_entity_using_expando_model()
160160
assert result.foo == 1
161161

162162

163163
def test_get_properties_defined_on_expando(testbed):
164164
result = snippets.get_properties_defined_on_expando(
165-
snippets.create_expando_model())
165+
snippets.create_entity_using_expando_model())
166166
assert result['foo'] is not None
167167
assert result['bar'] is not None
168168
assert result['tags'] is not None
169169

170170

171-
def test_create_expando_model_with_defined_properties(testbed):
172-
result = snippets.create_expando_model_with_defined_properties()
171+
def test_create_entity_using_expando_model_with_defined_properties(testbed):
172+
result = snippets.create_expando_model_entity_with_defined_properties()
173173
assert result.name == 'Sandy'
174174

175175

176-
def test_create_expando_model_that_isnt_indexed_by_default(testbed):
177-
result = snippets.create_expando_model_that_isnt_indexed_by_default()
176+
def test_create_expando_model_entity_that_isnt_indexed_by_default(testbed):
177+
result = (
178+
snippets.create_expando_model_entity_that_isnt_indexed_by_default())
178179
assert result['foo']
179180
assert result['bar']
180181

0 commit comments

Comments
 (0)