@@ -243,14 +243,45 @@ def test_get_explicit_connection_hit(self):
243243 self .assertEqual (entity .items (), [('foo' , 'Foo' )])
244244 self .assertTrue (entity .key () is key )
245245
246- def test_get_explicit_connection_partial_key (self ):
246+ def test_get_no_connection (self ):
247+ from gcloud .datastore import _implicit_environ
248+
249+ self .assertEqual (_implicit_environ .CONNECTION , None )
250+ key = self ._makeOne ('KIND' , 1234 )
251+ with self .assertRaises (AttributeError ):
252+ key .get ()
253+
254+ def test_delete_explicit_connection (self ):
247255 from gcloud .datastore .test_dataset import _Connection
248256
249- cnxn_lookup_result = []
250- cnxn = _Connection (* cnxn_lookup_result )
251- key = self ._makeOne ('KIND' )
252- with self .assertRaises (ValueError ):
253- key .get (connection = cnxn )
257+ cnxn = _Connection ()
258+ key = self ._makeOne ('KIND' , 1234 )
259+ result = key .delete (connection = cnxn )
260+ self .assertEqual (result , None )
261+ self .assertEqual (cnxn ._called_dataset_id , self ._DEFAULT_DATASET )
262+ self .assertEqual (cnxn ._called_key_pbs , [key .to_protobuf ()])
263+
264+ def test_delete_implicit_connection (self ):
265+ from gcloud ._testing import _Monkey
266+ from gcloud .datastore import _implicit_environ
267+ from gcloud .datastore .test_dataset import _Connection
268+
269+ cnxn = _Connection ()
270+ key = self ._makeOne ('KIND' , 1234 )
271+ with _Monkey (_implicit_environ , CONNECTION = cnxn ):
272+ result = key .delete ()
273+
274+ self .assertEqual (result , None )
275+ self .assertEqual (cnxn ._called_dataset_id , self ._DEFAULT_DATASET )
276+ self .assertEqual (cnxn ._called_key_pbs , [key .to_protobuf ()])
277+
278+ def test_delete_no_connection (self ):
279+ from gcloud .datastore import _implicit_environ
280+
281+ self .assertEqual (_implicit_environ .CONNECTION , None )
282+ key = self ._makeOne ('KIND' , 1234 )
283+ with self .assertRaises (AttributeError ):
284+ key .delete ()
254285
255286 def test_is_partial_no_name_or_id (self ):
256287 key = self ._makeOne ('KIND' )
0 commit comments