@@ -696,8 +696,8 @@ def test_commit_wo_transaction(self):
696696 from google .cloud .grpc .datastore .v1 import datastore_pb2
697697 from google .cloud .datastore .helpers import _new_value_pb
698698
699- PROJECT = 'PROJECT'
700- key_pb = self ._make_key_pb (PROJECT )
699+ project = 'PROJECT'
700+ key_pb = self ._make_key_pb (project )
701701 rsp_pb = datastore_pb2 .CommitResponse ()
702702 req_pb = datastore_pb2 .CommitRequest ()
703703 mutation = req_pb .mutations .add ()
@@ -708,44 +708,32 @@ def test_commit_wo_transaction(self):
708708 http = Http ({'status' : '200' }, rsp_pb .SerializeToString ())
709709 client = mock .Mock (_http = http , spec = ['_http' ])
710710 conn = self ._make_one (client )
711- URI = '/' .join ([
711+ uri = '/' .join ([
712712 conn .api_base_url ,
713713 conn .API_VERSION ,
714714 'projects' ,
715- PROJECT + ':commit' ,
715+ project + ':commit' ,
716716 ])
717717
718- # Set up mock for parsing the response.
719- expected_result = object ()
720- _parsed = []
721-
722- def mock_parse (response ):
723- _parsed .append (response )
724- return expected_result
725-
726- patch = mock .patch (
727- 'google.cloud.datastore._http._parse_commit_response' ,
728- new = mock_parse )
729- with patch :
730- result = conn .commit (PROJECT , req_pb , None )
718+ result = conn .commit (project , req_pb , None )
719+ self .assertEqual (result , rsp_pb )
731720
732- self . assertIs ( result , expected_result )
721+ # Verify the caller.
733722 cw = http ._called_with
734- self ._verify_protobuf_call (cw , URI , conn )
723+ self ._verify_protobuf_call (cw , uri , conn )
735724 rq_class = datastore_pb2 .CommitRequest
736725 request = rq_class ()
737726 request .ParseFromString (cw ['body' ])
738727 self .assertEqual (request .transaction , b'' )
739728 self .assertEqual (list (request .mutations ), [mutation ])
740729 self .assertEqual (request .mode , rq_class .NON_TRANSACTIONAL )
741- self .assertEqual (_parsed , [rsp_pb ])
742730
743731 def test_commit_w_transaction (self ):
744732 from google .cloud .grpc .datastore .v1 import datastore_pb2
745733 from google .cloud .datastore .helpers import _new_value_pb
746734
747- PROJECT = 'PROJECT'
748- key_pb = self ._make_key_pb (PROJECT )
735+ project = 'PROJECT'
736+ key_pb = self ._make_key_pb (project )
749737 rsp_pb = datastore_pb2 .CommitResponse ()
750738 req_pb = datastore_pb2 .CommitRequest ()
751739 mutation = req_pb .mutations .add ()
@@ -756,37 +744,25 @@ def test_commit_w_transaction(self):
756744 http = Http ({'status' : '200' }, rsp_pb .SerializeToString ())
757745 client = mock .Mock (_http = http , spec = ['_http' ])
758746 conn = self ._make_one (client )
759- URI = '/' .join ([
747+ uri = '/' .join ([
760748 conn .api_base_url ,
761749 conn .API_VERSION ,
762750 'projects' ,
763- PROJECT + ':commit' ,
751+ project + ':commit' ,
764752 ])
765753
766- # Set up mock for parsing the response.
767- expected_result = object ()
768- _parsed = []
754+ result = conn .commit (project , req_pb , b'xact' )
755+ self .assertEqual (result , rsp_pb )
769756
770- def mock_parse (response ):
771- _parsed .append (response )
772- return expected_result
773-
774- patch = mock .patch (
775- 'google.cloud.datastore._http._parse_commit_response' ,
776- new = mock_parse )
777- with patch :
778- result = conn .commit (PROJECT , req_pb , b'xact' )
779-
780- self .assertIs (result , expected_result )
757+ # Verify the caller.
781758 cw = http ._called_with
782- self ._verify_protobuf_call (cw , URI , conn )
759+ self ._verify_protobuf_call (cw , uri , conn )
783760 rq_class = datastore_pb2 .CommitRequest
784761 request = rq_class ()
785762 request .ParseFromString (cw ['body' ])
786763 self .assertEqual (request .transaction , b'xact' )
787764 self .assertEqual (list (request .mutations ), [mutation ])
788765 self .assertEqual (request .mode , rq_class .TRANSACTIONAL )
789- self .assertEqual (_parsed , [rsp_pb ])
790766
791767 def test_rollback_ok (self ):
792768 from google .cloud .grpc .datastore .v1 import datastore_pb2
@@ -870,46 +846,6 @@ def test_allocate_ids_non_empty(self):
870846 self .assertEqual (key_before , key_after )
871847
872848
873- class Test__parse_commit_response (unittest .TestCase ):
874-
875- def _call_fut (self , commit_response_pb ):
876- from google .cloud .datastore ._http import _parse_commit_response
877-
878- return _parse_commit_response (commit_response_pb )
879-
880- def test_it (self ):
881- from google .cloud .grpc .datastore .v1 import datastore_pb2
882- from google .cloud .grpc .datastore .v1 import entity_pb2
883-
884- index_updates = 1337
885- keys = [
886- entity_pb2 .Key (
887- path = [
888- entity_pb2 .Key .PathElement (
889- kind = 'Foo' ,
890- id = 1234 ,
891- ),
892- ],
893- ),
894- entity_pb2 .Key (
895- path = [
896- entity_pb2 .Key .PathElement (
897- kind = 'Bar' ,
898- name = 'baz' ,
899- ),
900- ],
901- ),
902- ]
903- response = datastore_pb2 .CommitResponse (
904- mutation_results = [
905- datastore_pb2 .MutationResult (key = key ) for key in keys
906- ],
907- index_updates = index_updates ,
908- )
909- result = self ._call_fut (response )
910- self .assertEqual (result , (index_updates , keys ))
911-
912-
913849class Http (object ):
914850
915851 _called_with = None
0 commit comments