Skip to content

Commit

Permalink
Enforce that / lists passed as arguments must be empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Dec 17, 2014
1 parent 5ab96e8 commit f11fa24
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ def lookup(self, dataset_id, key_pbs, missing=None, deferred=None):
If multiple keys were provided and no results matched,
this will return an empty list.
"""
if missing is not None and missing != []:
raise ValueError('missing must be None or an empty list')

if deferred is not None and deferred != []:
raise ValueError('deferred must be None or an empty list')

lookup_request = datastore_pb.LookupRequest()

single_key = isinstance(key_pbs, datastore_pb.Key)
Expand Down
20 changes: 20 additions & 0 deletions gcloud/datastore/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ def test_lookup_multiple_keys_w_missing(self):
self.assertEqual(keys[0], key_pb1)
self.assertEqual(keys[1], key_pb2)

def test_lookup_multiple_keys_w_missing_non_empty(self):
from gcloud.datastore.key import Key
DATASET_ID = 'DATASET'
key_pb1 = Key(path=[{'kind': 'Kind', 'id': 1234}]).to_protobuf()
key_pb2 = Key(path=[{'kind': 'Kind', 'id': 2345}]).to_protobuf()
conn = self._makeOne()
missing = ['this', 'list', 'is', 'not', 'empty']
self.assertRaises(ValueError,
conn.lookup, DATASET_ID, [key_pb1, key_pb2], missing=missing)

def test_lookup_multiple_keys_w_deferred(self):
from gcloud.datastore.connection import datastore_pb
from gcloud.datastore.key import Key
Expand Down Expand Up @@ -368,6 +378,16 @@ def test_lookup_multiple_keys_w_deferred(self):
self.assertEqual(keys[0], key_pb1)
self.assertEqual(keys[1], key_pb2)

def test_lookup_multiple_keys_w_deferred_non_empty(self):
from gcloud.datastore.key import Key
DATASET_ID = 'DATASET'
key_pb1 = Key(path=[{'kind': 'Kind', 'id': 1234}]).to_protobuf()
key_pb2 = Key(path=[{'kind': 'Kind', 'id': 2345}]).to_protobuf()
conn = self._makeOne()
deferred = ['this', 'list', 'is', 'not', 'empty']
self.assertRaises(ValueError,
conn.lookup, DATASET_ID, [key_pb1, key_pb2], deferred=deferred)

def test_lookup_multiple_keys_w_deferred_from_backend_but_not_passed(self):
from gcloud.datastore.connection import datastore_pb
from gcloud.datastore.key import Key
Expand Down

0 comments on commit f11fa24

Please sign in to comment.