@@ -59,37 +59,31 @@ def test_unpickleable(self):
5959 with self .assertRaises (pickle .PicklingError ):
6060 pickle .dumps (client_obj )
6161
62- def test_ctor_defaults (self ):
63- from google .cloud ._testing import _Monkey
64- from google .cloud import client
65-
66- CREDENTIALS = _make_credentials ()
67- FUNC_CALLS = []
68-
69- def mock_get_credentials ():
70- FUNC_CALLS .append ('get_credentials' )
71- return CREDENTIALS
62+ def test_constructor_defaults (self ):
63+ credentials = _make_credentials ()
7264
73- with _Monkey (client , get_credentials = mock_get_credentials ):
65+ patch = mock .patch (
66+ 'google.auth.default' , return_value = (credentials , None ))
67+ with patch as default :
7468 client_obj = self ._make_one ()
7569
76- self .assertIs (client_obj ._credentials , CREDENTIALS )
70+ self .assertIs (client_obj ._credentials , credentials )
7771 self .assertIsNone (client_obj ._http_internal )
78- self . assertEqual ( FUNC_CALLS , [ 'get_credentials' ] )
72+ default . assert_called_once_with ( )
7973
80- def test_ctor_explicit (self ):
81- CREDENTIALS = _make_credentials ()
82- HTTP = object ()
83- client_obj = self ._make_one (credentials = CREDENTIALS , _http = HTTP )
74+ def test_constructor_explicit (self ):
75+ credentials = _make_credentials ()
76+ http = mock . sentinel . http
77+ client_obj = self ._make_one (credentials = credentials , _http = http )
8478
85- self .assertIs (client_obj ._credentials , CREDENTIALS )
86- self .assertIs (client_obj ._http_internal , HTTP )
79+ self .assertIs (client_obj ._credentials , credentials )
80+ self .assertIs (client_obj ._http_internal , http )
8781
88- def test_ctor_bad_credentials (self ):
89- CREDENTIALS = object ()
82+ def test_constructor_bad_credentials (self ):
83+ credentials = mock . sentinel . credentials
9084
9185 with self .assertRaises (ValueError ):
92- self ._make_one (credentials = CREDENTIALS )
86+ self ._make_one (credentials = credentials )
9387
9488 def test_from_service_account_json (self ):
9589 from google .cloud import _helpers
@@ -162,34 +156,27 @@ def _get_target_class():
162156 def _make_one (self , * args , ** kw ):
163157 return self ._get_target_class ()(* args , ** kw )
164158
165- def test_ctor_defaults (self ):
166- from google .cloud ._testing import _Monkey
167- from google .cloud import client
168-
169- PROJECT = 'PROJECT'
170- CREDENTIALS = _make_credentials ()
171- FUNC_CALLS = []
172-
173- def mock_determine_proj (project ):
174- FUNC_CALLS .append ((project , '_determine_default_project' ))
175- return PROJECT
159+ def test_constructor_defaults (self ):
160+ credentials = _make_credentials ()
161+ patch1 = mock .patch (
162+ 'google.auth.default' , return_value = (credentials , None ))
176163
177- def mock_get_credentials ():
178- FUNC_CALLS .append ('get_credentials' )
179- return CREDENTIALS
164+ project = 'prahj-ekt'
165+ patch2 = mock .patch (
166+ 'google.cloud.client._determine_default_project' ,
167+ return_value = project )
180168
181- with _Monkey ( client , get_credentials = mock_get_credentials ,
182- _determine_default_project = mock_determine_proj ) :
183- client_obj = self ._make_one ()
169+ with patch1 as default :
170+ with patch2 as _determine_default_project :
171+ client_obj = self ._make_one ()
184172
185- self .assertEqual (client_obj .project , PROJECT )
186- self .assertIs (client_obj ._credentials , CREDENTIALS )
173+ self .assertEqual (client_obj .project , project )
174+ self .assertIs (client_obj ._credentials , credentials )
187175 self .assertIsNone (client_obj ._http_internal )
188- self .assertEqual (
189- FUNC_CALLS ,
190- [(None , '_determine_default_project' ), 'get_credentials' ])
176+ default .assert_called_once_with ()
177+ _determine_default_project .assert_called_once_with (None )
191178
192- def test_ctor_missing_project (self ):
179+ def test_constructor_missing_project (self ):
193180 from google .cloud ._testing import _Monkey
194181 from google .cloud import client
195182
@@ -204,7 +191,7 @@ def mock_determine_proj(project):
204191
205192 self .assertEqual (FUNC_CALLS , [(None , '_determine_default_project' )])
206193
207- def test_ctor_w_invalid_project (self ):
194+ def test_constructor_w_invalid_project (self ):
208195 CREDENTIALS = _make_credentials ()
209196 HTTP = object ()
210197 with self .assertRaises (ValueError ):
@@ -227,11 +214,11 @@ def _explicit_ctor_helper(self, project):
227214 self .assertIs (client_obj ._credentials , CREDENTIALS )
228215 self .assertIs (client_obj ._http_internal , HTTP )
229216
230- def test_ctor_explicit_bytes (self ):
217+ def test_constructor_explicit_bytes (self ):
231218 PROJECT = b'PROJECT'
232219 self ._explicit_ctor_helper (PROJECT )
233220
234- def test_ctor_explicit_unicode (self ):
221+ def test_constructor_explicit_unicode (self ):
235222 PROJECT = u'PROJECT'
236223 self ._explicit_ctor_helper (PROJECT )
237224
0 commit comments