@@ -684,8 +684,8 @@ def test_commit_wo_transaction(self):
684684 from google .cloud .grpc .datastore .v1 import datastore_pb2
685685 from google .cloud .datastore .helpers import _new_value_pb
686686
687- PROJECT = 'PROJECT'
688- key_pb = self ._make_key_pb (PROJECT )
687+ project = 'PROJECT'
688+ key_pb = self ._make_key_pb (project )
689689 rsp_pb = datastore_pb2 .CommitResponse ()
690690 req_pb = datastore_pb2 .CommitRequest ()
691691 mutation = req_pb .mutations .add ()
@@ -696,44 +696,32 @@ def test_commit_wo_transaction(self):
696696 http = Http ({'status' : '200' }, rsp_pb .SerializeToString ())
697697 client = mock .Mock (_http = http , spec = ['_http' ])
698698 conn = self ._make_one (client )
699- URI = '/' .join ([
699+ uri = '/' .join ([
700700 conn .api_base_url ,
701701 conn .API_VERSION ,
702702 'projects' ,
703- PROJECT + ':commit' ,
703+ project + ':commit' ,
704704 ])
705705
706- # Set up mock for parsing the response.
707- expected_result = object ()
708- _parsed = []
709-
710- def mock_parse (response ):
711- _parsed .append (response )
712- return expected_result
713-
714- patch = mock .patch (
715- 'google.cloud.datastore._http._parse_commit_response' ,
716- new = mock_parse )
717- with patch :
718- result = conn .commit (PROJECT , req_pb , None )
706+ result = conn .commit (project , req_pb , None )
707+ self .assertEqual (result , rsp_pb )
719708
720- self . assertIs ( result , expected_result )
709+ # Verify the caller.
721710 cw = http ._called_with
722- self ._verifyProtobufCall (cw , URI , conn )
711+ self ._verifyProtobufCall (cw , uri , conn )
723712 rq_class = datastore_pb2 .CommitRequest
724713 request = rq_class ()
725714 request .ParseFromString (cw ['body' ])
726715 self .assertEqual (request .transaction , b'' )
727716 self .assertEqual (list (request .mutations ), [mutation ])
728717 self .assertEqual (request .mode , rq_class .NON_TRANSACTIONAL )
729- self .assertEqual (_parsed , [rsp_pb ])
730718
731719 def test_commit_w_transaction (self ):
732720 from google .cloud .grpc .datastore .v1 import datastore_pb2
733721 from google .cloud .datastore .helpers import _new_value_pb
734722
735- PROJECT = 'PROJECT'
736- key_pb = self ._make_key_pb (PROJECT )
723+ project = 'PROJECT'
724+ key_pb = self ._make_key_pb (project )
737725 rsp_pb = datastore_pb2 .CommitResponse ()
738726 req_pb = datastore_pb2 .CommitRequest ()
739727 mutation = req_pb .mutations .add ()
@@ -744,37 +732,25 @@ def test_commit_w_transaction(self):
744732 http = Http ({'status' : '200' }, rsp_pb .SerializeToString ())
745733 client = mock .Mock (_http = http , spec = ['_http' ])
746734 conn = self ._make_one (client )
747- URI = '/' .join ([
735+ uri = '/' .join ([
748736 conn .api_base_url ,
749737 conn .API_VERSION ,
750738 'projects' ,
751- PROJECT + ':commit' ,
739+ project + ':commit' ,
752740 ])
753741
754- # Set up mock for parsing the response.
755- expected_result = object ()
756- _parsed = []
757-
758- def mock_parse (response ):
759- _parsed .append (response )
760- return expected_result
742+ result = conn .commit (project , req_pb , b'xact' )
743+ self .assertEqual (result , rsp_pb )
761744
762- patch = mock .patch (
763- 'google.cloud.datastore._http._parse_commit_response' ,
764- new = mock_parse )
765- with patch :
766- result = conn .commit (PROJECT , req_pb , b'xact' )
767-
768- self .assertIs (result , expected_result )
745+ # Verify the caller.
769746 cw = http ._called_with
770- self ._verifyProtobufCall (cw , URI , conn )
747+ self ._verifyProtobufCall (cw , uri , conn )
771748 rq_class = datastore_pb2 .CommitRequest
772749 request = rq_class ()
773750 request .ParseFromString (cw ['body' ])
774751 self .assertEqual (request .transaction , b'xact' )
775752 self .assertEqual (list (request .mutations ), [mutation ])
776753 self .assertEqual (request .mode , rq_class .TRANSACTIONAL )
777- self .assertEqual (_parsed , [rsp_pb ])
778754
779755 def test_rollback_ok (self ):
780756 from google .cloud .grpc .datastore .v1 import datastore_pb2
@@ -858,46 +834,6 @@ def test_allocate_ids_non_empty(self):
858834 self .assertEqual (key_before , key_after )
859835
860836
861- class Test__parse_commit_response (unittest .TestCase ):
862-
863- def _call_fut (self , commit_response_pb ):
864- from google .cloud .datastore ._http import _parse_commit_response
865-
866- return _parse_commit_response (commit_response_pb )
867-
868- def test_it (self ):
869- from google .cloud .grpc .datastore .v1 import datastore_pb2
870- from google .cloud .grpc .datastore .v1 import entity_pb2
871-
872- index_updates = 1337
873- keys = [
874- entity_pb2 .Key (
875- path = [
876- entity_pb2 .Key .PathElement (
877- kind = 'Foo' ,
878- id = 1234 ,
879- ),
880- ],
881- ),
882- entity_pb2 .Key (
883- path = [
884- entity_pb2 .Key .PathElement (
885- kind = 'Bar' ,
886- name = 'baz' ,
887- ),
888- ],
889- ),
890- ]
891- response = datastore_pb2 .CommitResponse (
892- mutation_results = [
893- datastore_pb2 .MutationResult (key = key ) for key in keys
894- ],
895- index_updates = index_updates ,
896- )
897- result = self ._call_fut (response )
898- self .assertEqual (result , (index_updates , keys ))
899-
900-
901837class Http (object ):
902838
903839 _called_with = None
0 commit comments