@@ -101,23 +101,15 @@ def test_get_no_keys(self):
101101 results = self ._callFUT ([])
102102 self .assertEqual (results , [])
103103
104- def _miss_helper (self , expected_results , use_list = True ):
104+ def test_get_miss (self ):
105105 from gcloud .datastore .key import Key
106106 from gcloud .datastore .test_connection import _Connection
107107
108108 DATASET_ID = 'DATASET'
109109 connection = _Connection ()
110110 key = Key ('Kind' , 1234 , dataset_id = DATASET_ID )
111- if use_list :
112- key = [key ]
113- results = self ._callFUT (key , connection = connection )
114- self .assertEqual (results , expected_results )
115-
116- def test_get_miss (self ):
117- self ._miss_helper ([], use_list = True )
118-
119- def test_get_miss_single_key (self ):
120- self ._miss_helper (None , use_list = False )
111+ results = self ._callFUT ([key ], connection = connection )
112+ self .assertEqual (results , [])
121113
122114 def test_get_miss_w_missing (self ):
123115 from gcloud .datastore import datastore_v1_pb2 as datastore_pb
@@ -248,33 +240,6 @@ def test_get_hit_multiple_keys_different_dataset(self):
248240 with self .assertRaises (ValueError ):
249241 self ._callFUT ([key1 , key2 ], connection = object ())
250242
251- def test_get_hit_single_key (self ):
252- from gcloud .datastore .key import Key
253- from gcloud .datastore .test_connection import _Connection
254-
255- DATASET_ID = 'DATASET'
256- KIND = 'Kind'
257- ID = 1234
258- PATH = [{'kind' : KIND , 'id' : ID }]
259-
260- # Make a found entity pb to be returned from mock backend.
261- entity_pb = self ._make_entity_pb (DATASET_ID , KIND , ID ,
262- 'foo' , 'Foo' )
263-
264- # Make a connection to return the entity pb.
265- connection = _Connection (entity_pb )
266-
267- key = Key (KIND , ID , dataset_id = DATASET_ID )
268- result = self ._callFUT (key , connection = connection )
269- new_key = result .key
270-
271- # Check the returned value is as expected.
272- self .assertFalse (new_key is key )
273- self .assertEqual (new_key .dataset_id , DATASET_ID )
274- self .assertEqual (new_key .path , PATH )
275- self .assertEqual (list (result ), ['foo' ])
276- self .assertEqual (result ['foo' ], 'Foo' )
277-
278243 def test_get_implicit (self ):
279244 from gcloud .datastore import _implicit_environ
280245 from gcloud .datastore .key import Key
@@ -313,6 +278,98 @@ def test_get_implicit(self):
313278 self .assertEqual (result ['foo' ], 'Foo' )
314279
315280
281+ class Test_delete_function (unittest2 .TestCase ):
282+
283+ def _callFUT (self , keys , connection = None ):
284+ from gcloud .datastore .api import delete
285+ return delete (keys , connection = connection )
286+
287+ def test_delete_no_batch (self ):
288+ from gcloud .datastore .test_batch import _Connection
289+ from gcloud .datastore .test_batch import _Key
290+
291+ # Build basic mocks needed to delete.
292+ _DATASET = 'DATASET'
293+ connection = _Connection ()
294+ key = _Key (_DATASET )
295+
296+ result = self ._callFUT ([key ], connection = connection )
297+ self .assertEqual (result , None )
298+
299+ def test_delete_existing_batch (self ):
300+ from gcloud ._testing import _Monkey
301+ from gcloud .datastore import api
302+ from gcloud .datastore .batch import _Batches
303+ from gcloud .datastore .batch import Batch
304+ from gcloud .datastore .test_batch import _Connection
305+ from gcloud .datastore .test_batch import _Key
306+
307+ # Build basic mocks needed to delete.
308+ _DATASET = 'DATASET'
309+ connection = _Connection ()
310+ key = _Key (_DATASET )
311+
312+ # Set up mock Batch on stack so we can check it is used.
313+ _BATCHES = _Batches ()
314+ CURR_BATCH = Batch (dataset_id = _DATASET , connection = connection )
315+ _BATCHES .push (CURR_BATCH )
316+
317+ with _Monkey (api , _BATCHES = _BATCHES ):
318+ result = self ._callFUT ([key ], connection = connection )
319+
320+ self .assertEqual (result , None )
321+ self .assertEqual (
322+ connection ._deleted ,
323+ [(_DATASET , [key ._key ], CURR_BATCH .mutation )])
324+
325+ def test_delete_implicit_connection (self ):
326+ from gcloud ._testing import _Monkey
327+ from gcloud .datastore import _implicit_environ
328+ from gcloud .datastore import api
329+ from gcloud .datastore .batch import _Batches
330+ from gcloud .datastore .batch import Batch
331+ from gcloud .datastore .test_batch import _Connection
332+ from gcloud .datastore .test_batch import _Key
333+
334+ # Build basic mocks needed to delete.
335+ _DATASET = 'DATASET'
336+ connection = _Connection ()
337+ key = _Key (_DATASET )
338+
339+ # Set up mock Batch on stack so we can check it is used.
340+ _BATCHES = _Batches ()
341+
342+ with _Monkey (_implicit_environ , CONNECTION = connection ):
343+ CURR_BATCH = Batch (dataset_id = _DATASET )
344+ _BATCHES .push (CURR_BATCH )
345+ with _Monkey (api , _BATCHES = _BATCHES ):
346+ result = self ._callFUT ([key ])
347+
348+ self .assertEqual (result , None )
349+ self .assertEqual (
350+ connection ._deleted ,
351+ [(_DATASET , [key ._key ], CURR_BATCH .mutation )])
352+
353+ def test_delete_no_keys (self ):
354+ from gcloud .datastore import _implicit_environ
355+
356+ self .assertEqual (_implicit_environ .CONNECTION , None )
357+ result = self ._callFUT ([])
358+ self .assertEqual (result , None )
359+
360+ def test_delete_no_connection (self ):
361+ from gcloud .datastore import _implicit_environ
362+ from gcloud .datastore .test_batch import _Key
363+
364+ # Build basic mocks needed to delete.
365+ _DATASET = 'DATASET'
366+ key = _Key (_DATASET )
367+
368+ self .assertEqual (_implicit_environ .CONNECTION , None )
369+ with self .assertRaises (ValueError ):
370+ self ._callFUT ([key ])
371+
372+
316373class Test_allocate_ids_function (unittest2 .TestCase ):
317374
318375 def _callFUT (self , incomplete_key , num_ids , connection = None ):
0 commit comments