Skip to content

Commit

Permalink
Merge pull request #982 from tseaver/944-fix_system_tests
Browse files Browse the repository at this point in the history
Restore system-test fixes lost in merge.
  • Loading branch information
tseaver committed Jul 11, 2015
2 parents c8593bf + 95632ba commit 583d1ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 3 additions & 1 deletion gcloud/datastore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,11 @@ def query(self, **kwargs):
Passes our ``dataset_id``.
"""
if 'client' in kwargs:
raise TypeError('Cannot pass client')
if 'dataset_id' in kwargs:
raise TypeError('Cannot pass dataset_id')
kwargs['dataset_id'] = self.dataset_id
if 'namespace' not in kwargs:
kwargs['namespace'] = self.namespace
return Query(**kwargs)
return Query(self, **kwargs)
14 changes: 10 additions & 4 deletions gcloud/datastore/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,12 @@ def test_transaction(self):
self.assertEqual(xact.args, (client,))
self.assertEqual(xact.kwargs, {})

def test_query_w_client(self):
KIND = 'KIND'
client = self._makeOne()
other = self._makeOne()
self.assertRaises(TypeError, client.query, kind=KIND, client=other)

def test_query_w_dataset_id(self):
KIND = 'KIND'
client = self._makeOne()
Expand All @@ -683,7 +689,7 @@ def test_query_w_defaults(self):
query = client.query()

self.assertTrue(isinstance(query, _Dummy))
self.assertEqual(query.args, ())
self.assertEqual(query.args, (client,))
expected_kwargs = {
'dataset_id': self.DATASET_ID,
'namespace': None,
Expand Down Expand Up @@ -715,6 +721,7 @@ def test_query_explicit(self):
)

self.assertTrue(isinstance(query, _Dummy))
self.assertEqual(query.args, (client,))
kwargs = {
'dataset_id': self.DATASET_ID,
'kind': KIND,
Expand All @@ -725,7 +732,6 @@ def test_query_explicit(self):
'order': ORDER,
'group_by': GROUP_BY,
}
self.assertEqual(query.args, ())
self.assertEqual(query.kwargs, kwargs)

def test_query_w_namespace(self):
Expand All @@ -739,7 +745,7 @@ def test_query_w_namespace(self):
query = client.query(kind=KIND)

self.assertTrue(isinstance(query, _Dummy))
self.assertEqual(query.args, ())
self.assertEqual(query.args, (client,))
expected_kwargs = {
'dataset_id': self.DATASET_ID,
'namespace': NAMESPACE,
Expand All @@ -759,7 +765,7 @@ def test_query_w_namespace_collision(self):
query = client.query(kind=KIND, namespace=NAMESPACE2)

self.assertTrue(isinstance(query, _Dummy))
self.assertEqual(query.args, ())
self.assertEqual(query.args, (client,))
expected_kwargs = {
'dataset_id': self.DATASET_ID,
'namespace': NAMESPACE2,
Expand Down
10 changes: 5 additions & 5 deletions system_tests/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_post_with_generated_id(self):
self._generic_test_post()

def test_save_multiple(self):
with datastore.Transaction() as xact:
with client.transaction() as xact:
entity1 = self._get_post()
xact.put(entity1)
# Register entity to be deleted.
Expand All @@ -131,7 +131,7 @@ def test_save_multiple(self):
self.assertEqual(len(matches), 2)

def test_empty_kind(self):
query = datastore.Query(kind='Post')
query = client.query(kind='Post')
query.ancestor = self.PARENT
posts = list(query.fetch(limit=2))
self.assertEqual(posts, [])
Expand All @@ -149,7 +149,7 @@ def test_save_key_self_reference(self):
client.put(entity)
self.case_entities_to_delete.append(entity)

query = datastore.Query(kind='Person')
query = client.query(kind='Person')
# Adding ancestor to ensure consistency.
query.ancestor = parent_key
query.add_filter('linkedTo', '=', key)
Expand All @@ -167,7 +167,7 @@ def setUpClass(cls):
cls.ANCESTOR_KEY = datastore.Key(*populate_datastore.ANCESTOR)

def _base_query(self):
return datastore.Query(kind='Character', ancestor=self.ANCESTOR_KEY)
return client.query(kind='Character', ancestor=self.ANCESTOR_KEY)

def test_limit_queries(self):
limit = 5
Expand Down Expand Up @@ -330,7 +330,7 @@ def test_transaction(self):
entity = datastore.Entity(key=datastore.Key('Company', 'Google'))
entity['url'] = u'www.google.com'

with datastore.Transaction() as xact:
with client.transaction() as xact:
result = client.get(entity.key)
if result is None:
xact.put(entity)
Expand Down

0 comments on commit 583d1ce

Please sign in to comment.