@@ -97,7 +97,7 @@ def _get_target_class():
9797
9898 return _DatastoreAPIOverGRPC
9999
100- def _make_one (self , stub , connection = None , secure = True , mock_args = None ):
100+ def _make_one (self , stub , connection = None , secure = True ):
101101 if connection is None :
102102 connection = mock .Mock (
103103 credentials = object (),
@@ -106,27 +106,21 @@ def _make_one(self, stub, connection=None, secure=True, mock_args=None):
106106 spec = ['credentials' , 'host' , 'USER_AGENT' ],
107107 )
108108
109- if mock_args is None :
110- mock_args = []
111-
112- def mock_make_stub (* args ):
113- mock_args .append (args )
114- return stub
115-
116109 if secure :
117110 patch = mock .patch (
118111 'google.cloud.datastore._gax.make_secure_stub' ,
119- new = mock_make_stub )
112+ return_value = stub )
120113 else :
121114 patch = mock .patch (
122115 'google.cloud.datastore._gax.make_insecure_stub' ,
123- new = mock_make_stub )
116+ return_value = stub )
124117
125- with patch :
126- return self ._get_target_class ()(connection , secure )
118+ with patch as make_stub_mock :
119+ api_obj = self ._get_target_class ()(connection , secure )
120+ return api_obj , make_stub_mock
127121
128122 def test_constructor (self ):
129- from google .cloud .proto . datastore .v1 import datastore_pb2_grpc
123+ import google .cloud .datastore ._gax as MUT
130124
131125 conn = mock .Mock (
132126 credentials = object (),
@@ -136,17 +130,17 @@ def test_constructor(self):
136130 )
137131
138132 stub = _GRPCStub ()
139- mock_args = []
140- datastore_api = self ._make_one (stub , connection = conn ,
141- mock_args = mock_args )
142- self .assertIs (datastore_api ._stub , stub )
133+ datastore_api , make_stub_mock = self ._make_one (
134+ stub , connection = conn )
143135
144- self .assertEqual (mock_args , [(
136+ self .assertIs (datastore_api ._stub , stub )
137+ make_stub_mock .assert_called_once_with (
145138 conn .credentials ,
146139 conn .USER_AGENT ,
147- datastore_pb2_grpc .DatastoreStub ,
140+ MUT . datastore_pb2_grpc .DatastoreStub ,
148141 conn .host ,
149- )])
142+ extra_options = MUT ._GRPC_EXTRA_OPTIONS ,
143+ )
150144
151145 def test_constructor_insecure (self ):
152146 from google .cloud .proto .datastore .v1 import datastore_pb2_grpc
@@ -158,21 +152,19 @@ def test_constructor_insecure(self):
158152 )
159153
160154 stub = _GRPCStub ()
161- mock_args = []
162- datastore_api = self ._make_one (stub , connection = conn ,
163- secure = False ,
164- mock_args = mock_args )
165- self .assertIs (datastore_api ._stub , stub )
155+ datastore_api , make_stub_mock = self ._make_one (
156+ stub , connection = conn , secure = False )
166157
167- self .assertEqual (mock_args , [(
158+ self .assertIs (datastore_api ._stub , stub )
159+ make_stub_mock .assert_called_once_with (
168160 datastore_pb2_grpc .DatastoreStub ,
169161 conn .host ,
170- )])
162+ )
171163
172164 def test_lookup (self ):
173165 return_val = object ()
174166 stub = _GRPCStub (return_val )
175- datastore_api = self ._make_one (stub = stub )
167+ datastore_api , _ = self ._make_one (stub = stub )
176168
177169 request_pb = mock .Mock (project_id = None , spec = ['project_id' ])
178170 project = 'PROJECT'
@@ -185,7 +177,7 @@ def test_lookup(self):
185177 def test_run_query (self ):
186178 return_val = object ()
187179 stub = _GRPCStub (return_val )
188- datastore_api = self ._make_one (stub = stub )
180+ datastore_api , _ = self ._make_one (stub = stub )
189181
190182 request_pb = mock .Mock (project_id = None , spec = ['project_id' ])
191183 project = 'PROJECT'
@@ -197,7 +189,7 @@ def test_run_query(self):
197189
198190 def _run_query_failure_helper (self , exc , err_class ):
199191 stub = _GRPCStub (side_effect = exc )
200- datastore_api = self ._make_one (stub = stub )
192+ datastore_api , _ = self ._make_one (stub = stub )
201193
202194 request_pb = mock .Mock (project_id = None , spec = ['project_id' ])
203195 project = 'PROJECT'
@@ -225,7 +217,7 @@ def test_run_query_invalid_argument(self):
225217 def test_begin_transaction (self ):
226218 return_val = object ()
227219 stub = _GRPCStub (return_val )
228- datastore_api = self ._make_one (stub = stub )
220+ datastore_api , _ = self ._make_one (stub = stub )
229221
230222 request_pb = mock .Mock (project_id = None , spec = ['project_id' ])
231223 project = 'PROJECT'
@@ -239,7 +231,7 @@ def test_begin_transaction(self):
239231 def test_commit_success (self ):
240232 return_val = object ()
241233 stub = _GRPCStub (return_val )
242- datastore_api = self ._make_one (stub = stub )
234+ datastore_api , _ = self ._make_one (stub = stub )
243235
244236 request_pb = mock .Mock (project_id = None , spec = ['project_id' ])
245237 project = 'PROJECT'
@@ -252,7 +244,7 @@ def test_commit_success(self):
252244 def test_rollback (self ):
253245 return_val = object ()
254246 stub = _GRPCStub (return_val )
255- datastore_api = self ._make_one (stub = stub )
247+ datastore_api , _ = self ._make_one (stub = stub )
256248
257249 request_pb = mock .Mock (project_id = None , spec = ['project_id' ])
258250 project = 'PROJECT'
@@ -265,7 +257,7 @@ def test_rollback(self):
265257 def test_allocate_ids (self ):
266258 return_val = object ()
267259 stub = _GRPCStub (return_val )
268- datastore_api = self ._make_one (stub = stub )
260+ datastore_api , _ = self ._make_one (stub = stub )
269261
270262 request_pb = mock .Mock (project_id = None , spec = ['project_id' ])
271263 project = 'PROJECT'
0 commit comments