@@ -804,55 +804,68 @@ def test_rollback_ok(self):
804804 def test_allocate_ids_empty (self ):
805805 from google .cloud .proto .datastore .v1 import datastore_pb2
806806
807- PROJECT = 'PROJECT'
807+ project = 'PROJECT'
808808 rsp_pb = datastore_pb2 .AllocateIdsResponse ()
809+
810+ # Create mock HTTP and client with response.
809811 http = Http ({'status' : '200' }, rsp_pb .SerializeToString ())
810812 client = mock .Mock (_http = http , spec = ['_http' ])
813+
814+ # Make request.
811815 conn = self ._make_one (client )
812- URI = '/' .join ([
816+ response = conn .allocate_ids (project , [])
817+
818+ # Check the result and verify the callers.
819+ self .assertEqual (list (response .keys ), [])
820+ self .assertEqual (response , rsp_pb )
821+ uri = '/' .join ([
813822 conn .api_base_url ,
814823 conn .API_VERSION ,
815824 'projects' ,
816- PROJECT + ':allocateIds' ,
825+ project + ':allocateIds' ,
817826 ])
818- self .assertEqual (conn .allocate_ids (PROJECT , []), [])
819827 cw = http ._called_with
820- self ._verify_protobuf_call (cw , URI , conn )
821- rq_class = datastore_pb2 .AllocateIdsRequest
822- request = rq_class ()
828+ self ._verify_protobuf_call (cw , uri , conn )
829+ request = datastore_pb2 .AllocateIdsRequest ()
823830 request .ParseFromString (cw ['body' ])
824831 self .assertEqual (list (request .keys ), [])
825832
826833 def test_allocate_ids_non_empty (self ):
827834 from google .cloud .proto .datastore .v1 import datastore_pb2
828835
829- PROJECT = 'PROJECT'
836+ project = 'PROJECT'
830837 before_key_pbs = [
831- self ._make_key_pb (PROJECT , id_ = None ),
832- self ._make_key_pb (PROJECT , id_ = None ),
838+ self ._make_key_pb (project , id_ = None ),
839+ self ._make_key_pb (project , id_ = None ),
833840 ]
834841 after_key_pbs = [
835- self ._make_key_pb (PROJECT ),
836- self ._make_key_pb (PROJECT , id_ = 2345 ),
842+ self ._make_key_pb (project ),
843+ self ._make_key_pb (project , id_ = 2345 ),
837844 ]
838845 rsp_pb = datastore_pb2 .AllocateIdsResponse ()
839846 rsp_pb .keys .add ().CopyFrom (after_key_pbs [0 ])
840847 rsp_pb .keys .add ().CopyFrom (after_key_pbs [1 ])
848+
849+ # Create mock HTTP and client with response.
841850 http = Http ({'status' : '200' }, rsp_pb .SerializeToString ())
842851 client = mock .Mock (_http = http , spec = ['_http' ])
852+
853+ # Make request.
843854 conn = self ._make_one (client )
844- URI = '/' .join ([
855+ response = conn .allocate_ids (project , before_key_pbs )
856+
857+ # Check the result and verify the callers.
858+ self .assertEqual (list (response .keys ), after_key_pbs )
859+ self .assertEqual (response , rsp_pb )
860+ uri = '/' .join ([
845861 conn .api_base_url ,
846862 conn .API_VERSION ,
847863 'projects' ,
848- PROJECT + ':allocateIds' ,
864+ project + ':allocateIds' ,
849865 ])
850- self .assertEqual (conn .allocate_ids (PROJECT , before_key_pbs ),
851- after_key_pbs )
852866 cw = http ._called_with
853- self ._verify_protobuf_call (cw , URI , conn )
854- rq_class = datastore_pb2 .AllocateIdsRequest
855- request = rq_class ()
867+ self ._verify_protobuf_call (cw , uri , conn )
868+ request = datastore_pb2 .AllocateIdsRequest ()
856869 request .ParseFromString (cw ['body' ])
857870 self .assertEqual (len (request .keys ), len (before_key_pbs ))
858871 for key_before , key_after in zip (before_key_pbs , request .keys ):
0 commit comments