-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jerjou Cheng
committed
Apr 14, 2016
1 parent
63363da
commit d5401d2
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,15 @@ def create_model_using_attributes(): | |
return sandy | ||
|
||
|
||
def create_model_using_populate(): | ||
sandy = Account() | ||
sandy.populate( | ||
username='Sandy', | ||
userid=123, | ||
email='[email protected]') | ||
return sandy | ||
|
||
|
||
def demonstrate_model_constructor_type_checking(): | ||
bad = Account( | ||
username='Sandy', userid='not integer') # raises an exception | ||
|
@@ -50,6 +59,17 @@ def save_model(sandy): | |
return sandy_key | ||
|
||
|
||
def get_model(sandy_key): | ||
sandy = sandy_key.get() | ||
return sandy | ||
|
||
|
||
def get_key_kind_and_id(sandy_key): | ||
kind_string = sandy_key.kind() # returns 'Account' | ||
ident = sandy_key.id() # returns '2' | ||
return kind_string, ident | ||
|
||
|
||
def get_url_safe_key(sandy_key): | ||
url_string = sandy_key.urlsafe() | ||
return url_string | ||
|
@@ -123,6 +143,8 @@ def equivalent_ways_to_define_key_with_parent(): | |
ndb.Key('Revision', '1', parent=ndb.Key( | ||
'Message', 123, parent=ndb.Key('Account', '[email protected]'))) | ||
|
||
|
||
def create_root_key(): | ||
sandy_key = ndb.Key(Account, '[email protected]') | ||
return sandy_key | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,11 @@ def test_create_model_using_attributes(client): | |
assert isinstance(result, snippets.Account) | ||
|
||
|
||
def test_create_model_using_populate(client): | ||
result = snippets.create_model_using_populate() | ||
assert isinstance(result, snippets.Account) | ||
|
||
|
||
def test_demonstrate_model_constructor_type_checking(client): | ||
with pytest.raises(datastore_errors.BadValueError): | ||
snippets.demonstrate_model_constructor_type_checking() | ||
|
@@ -56,6 +61,21 @@ def test_save_model(client): | |
assert isinstance(result, snippets.ndb.Key) | ||
|
||
|
||
def test_get_model(client): | ||
sandy_key = snippets.save_model( | ||
snippets.create_model_using_keyword_arguments()) | ||
result = snippets.get_model(sandy_key) | ||
assert isinstance(result, snippets.Account) | ||
|
||
|
||
def test_get_key_kind_and_id(client): | ||
sandy_key = snippets.save_model( | ||
snippets.create_model_using_keyword_arguments()) | ||
kind_string, ident = snippets.get_key_kind_and_id(sandy_key) | ||
assert kind_string == 'Account' | ||
assert isinstance(ident, long) | ||
|
||
|
||
def test_get_url_safe_key(client): | ||
sandy_key = snippets.save_model( | ||
snippets.create_model_using_keyword_arguments()) | ||
|
@@ -121,7 +141,11 @@ def test_demonstrate_models_with_parent_hierarchy(client): | |
|
||
|
||
def test_equivalent_ways_to_define_key_with_parent(client): | ||
result = snippets.equivalent_ways_to_define_key_with_parent() | ||
snippets.equivalent_ways_to_define_key_with_parent() | ||
|
||
|
||
def test_create_root_key(client): | ||
result = snippets.create_root_key() | ||
assert result.id() == '[email protected]' | ||
|
||
|
||
|