GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Missed some ndb snippets by jerjou · Pull Request #260 · GoogleCloudPlatform/python-docs-samples

Missed some ndb snippets #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
jerjou merged 1 commit into master from ndb
Apr 14, 2016

Uh oh!

There was an error while loading. Please reload this page.

Merged

Missed some ndb snippets #260

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
d5401d2
Missed some ndb snippets
Apr 14, 2016
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

22 changes: 22 additions & 0 deletions 22 appengine/ndb/entities/snippets.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
26 changes: 25 additions & 1 deletion 26 appengine/ndb/entities/snippets_test.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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())
Expand Down Expand Up @@ -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]'


Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.