@@ -179,8 +179,7 @@ def _getTargetClass(self):
179179 return _DatastoreAPIOverGRPC
180180
181181 def _makeOne (self , stub , connection = None , secure = True , mock_args = None ):
182- from google .cloud ._testing import _Monkey
183- from google .cloud .datastore import _http as MUT
182+ import mock
184183
185184 if connection is None :
186185 connection = _Connection (None )
@@ -195,10 +194,15 @@ def mock_make_stub(*args):
195194 return stub
196195
197196 if secure :
198- to_monkey = {'make_secure_stub' : mock_make_stub }
197+ patch = mock .patch (
198+ 'google.cloud.datastore._http.make_secure_stub' ,
199+ new = mock_make_stub )
199200 else :
200- to_monkey = {'make_insecure_stub' : mock_make_stub }
201- with _Monkey (MUT , ** to_monkey ):
201+ patch = mock .patch (
202+ 'google.cloud.datastore._http.make_insecure_stub' ,
203+ new = mock_make_stub )
204+
205+ with patch :
202206 return self ._getTargetClass ()(connection , secure )
203207
204208 def test_constructor (self ):
@@ -369,9 +373,10 @@ def _make_query_pb(self, kind):
369373 return pb
370374
371375 def _makeOne (self , credentials = None , http = None , use_grpc = False ):
372- from google .cloud ._testing import _Monkey
373- from google .cloud .datastore import _http as MUT
374- with _Monkey (MUT , _USE_GRPC = use_grpc ):
376+ import mock
377+
378+ with mock .patch ('google.cloud.datastore._http._USE_GRPC' ,
379+ new = use_grpc ):
375380 return self ._getTargetClass ()(credentials = credentials , http = http )
376381
377382 def _verifyProtobufCall (self , called_with , URI , conn ):
@@ -388,15 +393,14 @@ def test_default_url(self):
388393 self .assertEqual (conn .api_base_url , klass .API_BASE_URL )
389394
390395 def test_custom_url_from_env (self ):
391- import os
392- from google .cloud ._testing import _Monkey
396+ import mock
393397 from google .cloud .connection import API_BASE_URL
394398 from google .cloud .environment_vars import GCD_HOST
395399
396400 HOST = 'CURR_HOST'
397401 fake_environ = {GCD_HOST : HOST }
398402
399- with _Monkey ( os , environ = fake_environ ):
403+ with mock . patch ( 'os.environ' , new = fake_environ ):
400404 conn = self ._makeOne ()
401405
402406 self .assertNotEqual (conn .api_base_url , API_BASE_URL )
@@ -407,8 +411,7 @@ def test_ctor_defaults(self):
407411 self .assertIsNone (conn .credentials )
408412
409413 def test_ctor_without_grpc (self ):
410- from google .cloud ._testing import _Monkey
411- from google .cloud .datastore import _http as MUT
414+ import mock
412415
413416 connections = []
414417 return_val = object ()
@@ -417,16 +420,18 @@ def mock_api(connection):
417420 connections .append (connection )
418421 return return_val
419422
420- with _Monkey (MUT , _DatastoreAPIOverHttp = mock_api ):
423+ patch = mock .patch (
424+ 'google.cloud.datastore._http._DatastoreAPIOverHttp' ,
425+ new = mock_api )
426+ with patch :
421427 conn = self ._makeOne (use_grpc = False )
422428
423429 self .assertIsNone (conn .credentials )
424430 self .assertIs (conn ._datastore_api , return_val )
425431 self .assertEqual (connections , [conn ])
426432
427433 def test_ctor_with_grpc (self ):
428- from google .cloud ._testing import _Monkey
429- from google .cloud .datastore import _http as MUT
434+ import mock
430435
431436 api_args = []
432437 return_val = object ()
@@ -435,7 +440,10 @@ def mock_api(connection, secure):
435440 api_args .append ((connection , secure ))
436441 return return_val
437442
438- with _Monkey (MUT , _DatastoreAPIOverGRPC = mock_api ):
443+ patch = mock .patch (
444+ 'google.cloud.datastore._http._DatastoreAPIOverGRPC' ,
445+ new = mock_api )
446+ with patch :
439447 conn = self ._makeOne (use_grpc = True )
440448
441449 self .assertIsNone (conn .credentials )
@@ -919,9 +927,8 @@ def test_begin_transaction(self):
919927 request .ParseFromString (cw ['body' ])
920928
921929 def test_commit_wo_transaction (self ):
922- from google . cloud . _testing import _Monkey
930+ import mock
923931 from google .cloud .datastore ._generated import datastore_pb2
924- from google .cloud .datastore import _http as MUT
925932 from google .cloud .datastore .helpers import _new_value_pb
926933
927934 PROJECT = 'PROJECT'
@@ -950,7 +957,10 @@ def mock_parse(response):
950957 _parsed .append (response )
951958 return expected_result
952959
953- with _Monkey (MUT , _parse_commit_response = mock_parse ):
960+ patch = mock .patch (
961+ 'google.cloud.datastore._http._parse_commit_response' ,
962+ new = mock_parse )
963+ with patch :
954964 result = conn .commit (PROJECT , req_pb , None )
955965
956966 self .assertIs (result , expected_result )
@@ -965,9 +975,8 @@ def mock_parse(response):
965975 self .assertEqual (_parsed , [rsp_pb ])
966976
967977 def test_commit_w_transaction (self ):
968- from google . cloud . _testing import _Monkey
978+ import mock
969979 from google .cloud .datastore ._generated import datastore_pb2
970- from google .cloud .datastore import _http as MUT
971980 from google .cloud .datastore .helpers import _new_value_pb
972981
973982 PROJECT = 'PROJECT'
@@ -996,7 +1005,10 @@ def mock_parse(response):
9961005 _parsed .append (response )
9971006 return expected_result
9981007
999- with _Monkey (MUT , _parse_commit_response = mock_parse ):
1008+ patch = mock .patch (
1009+ 'google.cloud.datastore._http._parse_commit_response' ,
1010+ new = mock_parse )
1011+ with patch :
10001012 result = conn .commit (PROJECT , req_pb , b'xact' )
10011013
10021014 self .assertIs (result , expected_result )
0 commit comments