Skip to content

Commit 17dd814

Browse files
committed
splitting integration tests for
1 parent 3479ed8 commit 17dd814

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

pandas/io/gbq.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def get_application_default_credentials(self):
180180
from apiclient.errors import HttpError
181181
try:
182182
from oauth2client.client import GoogleCredentials
183+
from oauth2client.client import HttpAccessTokenRefreshError
183184
from oauth2client.client import ApplicationDefaultCredentialsError
184185
except ImportError:
185186
return None
@@ -195,7 +196,8 @@ def get_application_default_credentials(self):
195196
job_data = {'configuration': {'query': {'query': 'SELECT 1'}}}
196197
try:
197198
jobs.insert(projectId=self.project_id, body=job_data).execute()
198-
except (AccessTokenRefreshError, HttpError, TypeError):
199+
except (HttpAccessTokenRefreshError, AccessTokenRefreshError,
200+
HttpError, TypeError):
199201
return None
200202
return credentials
201203

pandas/io/tests/test_gbq.py

+29-3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,27 @@ def _skip_if_no_private_key_contents():
5656
_skip_if_no_private_key_contents()
5757

5858

59+
def _skip_if_get_correct_default_credentials(can=False):
60+
got_credentials = False
61+
try:
62+
from oauth2client.client import GoogleCredentials
63+
from apiclient.discovery import build
64+
credentials = GoogleCredentials.get_application_default()
65+
bigquery_service = build('bigquery', 'v2', credentials=credentials)
66+
jobs = bigquery_service.jobs()
67+
job_data = {'configuration': {'query': {'query': 'SELECT 1'}}}
68+
jobs.insert(projectId=PROJECT_ID, body=job_data).execute()
69+
got_credentials = True
70+
except:
71+
pass
72+
if can and got_credentials:
73+
raise nose.SkipTest("Cannot get default_credentials "
74+
"from the environment!")
75+
if (not can) and (not got_credentials):
76+
raise nose.SkipTest("Can get default_credentials "
77+
"from the environment!")
78+
79+
5980
def _test_imports():
6081
global _GOOGLE_API_CLIENT_INSTALLED, _GOOGLE_API_CLIENT_VALID_VERSION, \
6182
_HTTPLIB2_INSTALLED, _SETUPTOOLS_INSTALLED
@@ -218,11 +239,16 @@ def test_should_be_able_to_get_results_from_query(self):
218239
schema, pages = self.sut.run_query('SELECT 1')
219240
self.assertTrue(pages is not None)
220241

221-
def test_get_application_default_credentials_should_not_throw_error(self):
242+
def test_get_application_default_credentials_does_not_throw_error(self):
243+
_skip_if_get_correct_default_credentials(can=True)
244+
credentials = self.sut.get_application_default_credentials()
245+
self.assertIsNone(credentials)
246+
247+
def test_get_application_default_credentials_returns_credentials(self):
248+
_skip_if_get_correct_default_credentials(can=False)
222249
from oauth2client.client import GoogleCredentials
223250
credentials = self.sut.get_application_default_credentials()
224-
valid_types = (type(None), GoogleCredentials)
225-
assert isinstance(credentials, valid_types)
251+
self.assertTrue(isinstance(credentials, GoogleCredentials))
226252

227253

228254
class TestGBQConnectorServiceAccountKeyPathIntegration(tm.TestCase):

0 commit comments

Comments
 (0)