@@ -231,6 +231,78 @@ def test_lookup_single_key_empty_response(self):
231231 self .assertEqual (len (keys ), 1 )
232232 self .assertEqual (keys [0 ], key_pb )
233233
234+ def test_lookup_single_key_empty_response_w_eventual (self ):
235+ from gcloud .datastore .connection import datastore_pb
236+ from gcloud .datastore .key import Key
237+
238+ DATASET_ID = 'DATASET'
239+ key_pb = Key (path = [{'kind' : 'Kind' , 'id' : 1234 }]).to_protobuf ()
240+ rsp_pb = datastore_pb .LookupResponse ()
241+ conn = self ._makeOne ()
242+ URI = '/' .join ([
243+ conn .API_BASE_URL ,
244+ 'datastore' ,
245+ conn .API_VERSION ,
246+ 'datasets' ,
247+ DATASET_ID ,
248+ 'lookup' ,
249+ ])
250+ http = conn ._http = Http ({'status' : '200' }, rsp_pb .SerializeToString ())
251+ self .assertEqual (conn .lookup (DATASET_ID , key_pb , eventual = True ), None )
252+ cw = http ._called_with
253+ self ._verifyProtobufCall (cw , URI , conn )
254+ rq_class = datastore_pb .LookupRequest
255+ request = rq_class ()
256+ request .ParseFromString (cw ['body' ])
257+ keys = list (request .key )
258+ self .assertEqual (len (keys ), 1 )
259+ self .assertEqual (keys [0 ], key_pb )
260+ ro_enum = datastore_pb .ReadOptions .ReadConsistency
261+ self .assertEqual (request .read_options .read_consistency ,
262+ ro_enum .Value ('EVENTUAL' ))
263+ self .assertEqual (request .read_options .transaction , '' )
264+
265+ def test_lookup_single_key_empty_response_w_eventual_and_transaction (self ):
266+ from gcloud .datastore .key import Key
267+
268+ DATASET_ID = 'DATASET'
269+ TRANSACTION = 'TRANSACTION'
270+ key_pb = Key (path = [{'kind' : 'Kind' , 'id' : 1234 }]).to_protobuf ()
271+ conn = self ._makeOne ()
272+ conn .transaction (TRANSACTION )
273+ self .assertRaises (
274+ ValueError , conn .lookup , DATASET_ID , key_pb , eventual = True )
275+
276+ def test_lookup_single_key_empty_response_w_transaction (self ):
277+ from gcloud .datastore .connection import datastore_pb
278+ from gcloud .datastore .key import Key
279+
280+ DATASET_ID = 'DATASET'
281+ TRANSACTION = 'TRANSACTION'
282+ key_pb = Key (path = [{'kind' : 'Kind' , 'id' : 1234 }]).to_protobuf ()
283+ rsp_pb = datastore_pb .LookupResponse ()
284+ conn = self ._makeOne ()
285+ conn .transaction (TRANSACTION )
286+ URI = '/' .join ([
287+ conn .API_BASE_URL ,
288+ 'datastore' ,
289+ conn .API_VERSION ,
290+ 'datasets' ,
291+ DATASET_ID ,
292+ 'lookup' ,
293+ ])
294+ http = conn ._http = Http ({'status' : '200' }, rsp_pb .SerializeToString ())
295+ self .assertEqual (conn .lookup (DATASET_ID , key_pb ), None )
296+ cw = http ._called_with
297+ self ._verifyProtobufCall (cw , URI , conn )
298+ rq_class = datastore_pb .LookupRequest
299+ request = rq_class ()
300+ request .ParseFromString (cw ['body' ])
301+ keys = list (request .key )
302+ self .assertEqual (len (keys ), 1 )
303+ self .assertEqual (keys [0 ], key_pb )
304+ self .assertEqual (request .read_options .transaction , TRANSACTION )
305+
234306 def test_lookup_single_key_nonempty_response (self ):
235307 from gcloud .datastore .connection import datastore_pb
236308 from gcloud .datastore .key import Key
@@ -443,6 +515,108 @@ def test_lookup_multiple_keys_w_deferred_from_backend_but_not_passed(self):
443515 self .assertEqual (len (keys ), 1 )
444516 self .assertEqual (keys [0 ], key_pb2 )
445517
518+ def test_run_query_w_eventual_no_transaction (self ):
519+ from gcloud .datastore .connection import datastore_pb
520+ from gcloud .datastore .query import Query
521+
522+ DATASET_ID = 'DATASET'
523+ KIND = 'Nonesuch'
524+ CURSOR = b'\x00 '
525+ q_pb = Query (KIND , DATASET_ID ).to_protobuf ()
526+ rsp_pb = datastore_pb .RunQueryResponse ()
527+ rsp_pb .batch .end_cursor = CURSOR
528+ no_more = datastore_pb .QueryResultBatch .NO_MORE_RESULTS
529+ rsp_pb .batch .more_results = no_more
530+ rsp_pb .batch .entity_result_type = datastore_pb .EntityResult .FULL
531+ conn = self ._makeOne ()
532+ URI = '/' .join ([
533+ conn .API_BASE_URL ,
534+ 'datastore' ,
535+ conn .API_VERSION ,
536+ 'datasets' ,
537+ DATASET_ID ,
538+ 'runQuery' ,
539+ ])
540+ http = conn ._http = Http ({'status' : '200' }, rsp_pb .SerializeToString ())
541+ pbs , end , more , skipped = conn .run_query (DATASET_ID , q_pb ,
542+ eventual = True )
543+ self .assertEqual (pbs , [])
544+ self .assertEqual (end , CURSOR )
545+ self .assertTrue (more )
546+ self .assertEqual (skipped , 0 )
547+ cw = http ._called_with
548+ self ._verifyProtobufCall (cw , URI , conn )
549+ rq_class = datastore_pb .RunQueryRequest
550+ request = rq_class ()
551+ request .ParseFromString (cw ['body' ])
552+ self .assertEqual (request .partition_id .namespace , '' )
553+ self .assertEqual (request .query , q_pb )
554+ ro_enum = datastore_pb .ReadOptions .ReadConsistency
555+ self .assertEqual (request .read_options .read_consistency ,
556+ ro_enum .Value ('EVENTUAL' ))
557+ self .assertEqual (request .read_options .transaction , '' )
558+
559+ def test_run_query_wo_eventual_w_transaction (self ):
560+ from gcloud .datastore .connection import datastore_pb
561+ from gcloud .datastore .query import Query
562+
563+ DATASET_ID = 'DATASET'
564+ KIND = 'Nonesuch'
565+ CURSOR = b'\x00 '
566+ TRANSACTION = 'TRANSACTION'
567+ q_pb = Query (KIND , DATASET_ID ).to_protobuf ()
568+ rsp_pb = datastore_pb .RunQueryResponse ()
569+ rsp_pb .batch .end_cursor = CURSOR
570+ no_more = datastore_pb .QueryResultBatch .NO_MORE_RESULTS
571+ rsp_pb .batch .more_results = no_more
572+ rsp_pb .batch .entity_result_type = datastore_pb .EntityResult .FULL
573+ conn = self ._makeOne ()
574+ conn .transaction (TRANSACTION )
575+ URI = '/' .join ([
576+ conn .API_BASE_URL ,
577+ 'datastore' ,
578+ conn .API_VERSION ,
579+ 'datasets' ,
580+ DATASET_ID ,
581+ 'runQuery' ,
582+ ])
583+ http = conn ._http = Http ({'status' : '200' }, rsp_pb .SerializeToString ())
584+ pbs , end , more , skipped = conn .run_query (DATASET_ID , q_pb )
585+ self .assertEqual (pbs , [])
586+ self .assertEqual (end , CURSOR )
587+ self .assertTrue (more )
588+ self .assertEqual (skipped , 0 )
589+ cw = http ._called_with
590+ self ._verifyProtobufCall (cw , URI , conn )
591+ rq_class = datastore_pb .RunQueryRequest
592+ request = rq_class ()
593+ request .ParseFromString (cw ['body' ])
594+ self .assertEqual (request .partition_id .namespace , '' )
595+ self .assertEqual (request .query , q_pb )
596+ ro_enum = datastore_pb .ReadOptions .ReadConsistency
597+ self .assertEqual (request .read_options .read_consistency ,
598+ ro_enum .Value ('DEFAULT' ))
599+ self .assertEqual (request .read_options .transaction , TRANSACTION )
600+
601+ def test_run_query_w_eventual_and_transaction (self ):
602+ from gcloud .datastore .connection import datastore_pb
603+ from gcloud .datastore .query import Query
604+
605+ DATASET_ID = 'DATASET'
606+ KIND = 'Nonesuch'
607+ CURSOR = b'\x00 '
608+ TRANSACTION = 'TRANSACTION'
609+ q_pb = Query (KIND , DATASET_ID ).to_protobuf ()
610+ rsp_pb = datastore_pb .RunQueryResponse ()
611+ rsp_pb .batch .end_cursor = CURSOR
612+ no_more = datastore_pb .QueryResultBatch .NO_MORE_RESULTS
613+ rsp_pb .batch .more_results = no_more
614+ rsp_pb .batch .entity_result_type = datastore_pb .EntityResult .FULL
615+ conn = self ._makeOne ()
616+ conn .transaction (TRANSACTION )
617+ self .assertRaises (
618+ ValueError , conn .run_query , DATASET_ID , q_pb , eventual = True )
619+
446620 def test_run_query_wo_namespace_empty_result (self ):
447621 from gcloud .datastore .connection import datastore_pb
448622 from gcloud .datastore .query import Query
0 commit comments