4343
4444LOAD_FILE_PATCH = mock .patch (
4545 'google.auth._default._load_credentials_from_file' , return_value = (
46- mock .sentinel .credentials , mock .sentinel .project_id ))
46+ mock .sentinel .credentials , mock .sentinel .project_id ), autospec = True )
4747
4848
4949def test__load_credentials_from_file_invalid_json (tmpdir ):
@@ -131,7 +131,9 @@ def test__get_explicit_environ_credentials_no_project_id(
131131
132132
133133@LOAD_FILE_PATCH
134- @mock .patch ('google.auth._cloud_sdk.get_application_default_credentials_path' )
134+ @mock .patch (
135+ 'google.auth._cloud_sdk.get_application_default_credentials_path' ,
136+ autospec = True )
135137def test__get_gcloud_sdk_credentials (
136138 mock_get_adc_path , mock_load ):
137139 mock_get_adc_path .return_value = SERVICE_ACCOUNT_FILE
@@ -143,7 +145,9 @@ def test__get_gcloud_sdk_credentials(
143145 mock_load .assert_called_with (SERVICE_ACCOUNT_FILE )
144146
145147
146- @mock .patch ('google.auth._cloud_sdk.get_application_default_credentials_path' )
148+ @mock .patch (
149+ 'google.auth._cloud_sdk.get_application_default_credentials_path' ,
150+ autospec = True )
147151def test__get_gcloud_sdk_credentials_non_existent (mock_get_adc_path , tmpdir ):
148152 non_existent = tmpdir .join ('non-existent' )
149153 mock_get_adc_path .return_value = str (non_existent )
@@ -156,7 +160,7 @@ def test__get_gcloud_sdk_credentials_non_existent(mock_get_adc_path, tmpdir):
156160
157161@mock .patch (
158162 'google.auth._cloud_sdk.get_project_id' ,
159- return_value = mock .sentinel .project_id )
163+ return_value = mock .sentinel .project_id , autospec = True )
160164@mock .patch ('os.path.isfile' , return_value = True )
161165@LOAD_FILE_PATCH
162166def test__get_gcloud_sdk_credentials_project_id (
@@ -174,7 +178,7 @@ def test__get_gcloud_sdk_credentials_project_id(
174178
175179@mock .patch (
176180 'google.auth._cloud_sdk.get_project_id' ,
177- return_value = None )
181+ return_value = None , autospec = True )
178182@mock .patch ('os.path.isfile' , return_value = True )
179183@LOAD_FILE_PATCH
180184def test__get_gcloud_sdk_credentials_no_project_id (
@@ -212,18 +216,21 @@ def test__get_gae_credentials_no_apis():
212216
213217
214218@mock .patch (
215- 'google.auth.compute_engine._metadata.ping' , return_value = True )
219+ 'google.auth.compute_engine._metadata.ping' , return_value = True ,
220+ autospec = True )
216221@mock .patch (
217222 'google.auth.compute_engine._metadata.get_project_id' ,
218- return_value = 'example-project' )
223+ return_value = 'example-project' , autospec = True )
219224def test__get_gce_credentials (get_mock , ping_mock ):
220225 credentials , project_id = _default ._get_gce_credentials ()
221226
222227 assert isinstance (credentials , compute_engine .Credentials )
223228 assert project_id == 'example-project'
224229
225230
226- @mock .patch ('google.auth.compute_engine._metadata.ping' , return_value = False )
231+ @mock .patch (
232+ 'google.auth.compute_engine._metadata.ping' , return_value = False ,
233+ autospec = True )
227234def test__get_gce_credentials_no_ping (ping_mock ):
228235 credentials , project_id = _default ._get_gce_credentials ()
229236
@@ -232,34 +239,39 @@ def test__get_gce_credentials_no_ping(ping_mock):
232239
233240
234241@mock .patch (
235- 'google.auth.compute_engine._metadata.ping' , return_value = True )
242+ 'google.auth.compute_engine._metadata.ping' , return_value = True ,
243+ autospec = True )
236244@mock .patch (
237245 'google.auth.compute_engine._metadata.get_project_id' ,
238- side_effect = exceptions .TransportError ())
246+ side_effect = exceptions .TransportError (), autospec = True )
239247def test__get_gce_credentials_no_project_id (get_mock , ping_mock ):
240248 credentials , project_id = _default ._get_gce_credentials ()
241249
242250 assert isinstance (credentials , compute_engine .Credentials )
243251 assert project_id is None
244252
245253
246- @mock .patch ('google.auth.compute_engine._metadata.ping' , return_value = False )
254+ @mock .patch (
255+ 'google.auth.compute_engine._metadata.ping' , return_value = False ,
256+ autospec = True )
247257def test__get_gce_credentials_explicit_request (ping_mock ):
248258 _default ._get_gce_credentials (mock .sentinel .request )
249259 ping_mock .assert_called_with (request = mock .sentinel .request )
250260
251261
252262@mock .patch (
253263 'google.auth._default._get_explicit_environ_credentials' ,
254- return_value = (mock .sentinel .credentials , mock .sentinel .project_id ))
264+ return_value = (mock .sentinel .credentials , mock .sentinel .project_id ),
265+ autospec = True )
255266def test_default_early_out (get_mock ):
256267 assert _default .default () == (
257268 mock .sentinel .credentials , mock .sentinel .project_id )
258269
259270
260271@mock .patch (
261272 'google.auth._default._get_explicit_environ_credentials' ,
262- return_value = (mock .sentinel .credentials , mock .sentinel .project_id ))
273+ return_value = (mock .sentinel .credentials , mock .sentinel .project_id ),
274+ autospec = True )
263275def test_default_explict_project_id (get_mock , monkeypatch ):
264276 monkeypatch .setenv (environment_vars .PROJECT , 'explicit-env' )
265277 assert _default .default () == (
@@ -268,7 +280,8 @@ def test_default_explict_project_id(get_mock, monkeypatch):
268280
269281@mock .patch (
270282 'google.auth._default._get_explicit_environ_credentials' ,
271- return_value = (mock .sentinel .credentials , mock .sentinel .project_id ))
283+ return_value = (mock .sentinel .credentials , mock .sentinel .project_id ),
284+ autospec = True )
272285def test_default_explict_legacy_project_id (get_mock , monkeypatch ):
273286 monkeypatch .setenv (environment_vars .LEGACY_PROJECT , 'explicit-env' )
274287 assert _default .default () == (
@@ -277,26 +290,27 @@ def test_default_explict_legacy_project_id(get_mock, monkeypatch):
277290
278291@mock .patch (
279292 'google.auth._default._get_explicit_environ_credentials' ,
280- return_value = (None , None ))
293+ return_value = (None , None ), autospec = True )
281294@mock .patch (
282295 'google.auth._default._get_gcloud_sdk_credentials' ,
283- return_value = (None , None ))
296+ return_value = (None , None ), autospec = True )
284297@mock .patch (
285298 'google.auth._default._get_gae_credentials' ,
286- return_value = (None , None ))
299+ return_value = (None , None ), autospec = True )
287300@mock .patch (
288301 'google.auth._default._get_gce_credentials' ,
289- return_value = (None , None ))
302+ return_value = (None , None ), autospec = True )
290303def test_default_fail (unused_gce , unused_gae , unused_sdk , unused_explicit ):
291304 with pytest .raises (exceptions .DefaultCredentialsError ):
292305 assert _default .default ()
293306
294307
295308@mock .patch (
296309 'google.auth._default._get_explicit_environ_credentials' ,
297- return_value = (mock .sentinel .credentials , mock .sentinel .project_id ))
310+ return_value = (mock .sentinel .credentials , mock .sentinel .project_id ),
311+ autospec = True )
298312@mock .patch (
299- 'google.auth.credentials.with_scopes_if_required' )
313+ 'google.auth.credentials.with_scopes_if_required' , autospec = True )
300314def test_default_scoped (with_scopes_mock , get_mock ):
301315 scopes = ['one' , 'two' ]
302316
0 commit comments