Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(57)

Unified Diff: ndb/query_test.py

Issue 6133044: Projection queries for NDB (Closed)
Patch Set: merge RELEASE_NOTES Created 1 year, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ndb/query.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ndb/query_test.py
===================================================================
--- a/ndb/query_test.py
+++ b/ndb/query_test.py
@@ -260,6 +260,26 @@
self.assertRaises(datastore_errors.BadFilterError,
lambda: Emp.local == Foo(name='a'))
+ def testQueryWithProjection(self):
+ class Foo(model.Model):
+ p = model.IntegerProperty()
+ q = model.IntegerProperty(required=True)
+ r = model.IntegerProperty(repeated=True)
+ d = model.IntegerProperty(default=42)
+
+ key = Foo(p=1, q=2, r=[3, 4]).put()
+ q = Foo.query(Foo.p >= 0)
+ ent = q.get(projection=[Foo.p, 'q'])
+ self.assertTrue(ent._partial)
+ self.assertEqual(ent.p, 1)
+ self.assertEqual(ent.q, 2)
+ self.assertEqual(ent.r, [])
+ self.assertEqual(ent.d, 42)
+ ents = q.fetch(projection=['p', 'r'])
+ self.assertEqual(ents, [Foo(p=1, r=[3], key=key, partial=True),
+ Foo(p=1, r=[4], key=key, partial=True)])
+ self.assertRaises(datastore_errors.BadArgumentError, q.get, projection=[42])
+
def testFilterRepr(self):
class Employee(model.Model):
name = model.StringProperty()
@@ -1428,6 +1448,13 @@
q = Foo.gql("WHERE tags = :1 AND name = :foo AND rate = :bar")
self.assertEqual([1, 'bar', 'foo'], q.analyze())
+ def testGqlProjection(self):
+ q = query.gql("SELECT name, tags FROM Foo WHERE name < 'joe' ORDER BY name")
+ self.assertEqual(q.fetch(), [Foo(name='jill', tags=['jack'],
+ key=self.jill.key, partial=True),
+ Foo(name='jill', tags=['jill'],
+ key=self.jill.key, partial=True)])
+
def testAsyncNamespace(self):
# Test that async queries pick up the namespace when the
# foo_async() call is made, not later.
« no previous file with comments | « ndb/query.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1278:e6ce13d99bf5