@@ -56,32 +56,6 @@ def _skip_if_no_private_key_contents():
56
56
_skip_if_no_private_key_contents ()
57
57
58
58
59
- def _check_if_can_get_correct_default_credentials ():
60
- try :
61
- from oauth2client .client import GoogleCredentials
62
- from apiclient .discovery import build
63
- credentials = GoogleCredentials .get_application_default ()
64
- bigquery_service = build ('bigquery' , 'v2' , credentials = credentials )
65
- jobs = bigquery_service .jobs ()
66
- job_data = {'configuration' : {'query' : {'query' : 'SELECT 1' }}}
67
- jobs .insert (projectId = PROJECT_ID , body = job_data ).execute ()
68
- return True
69
- except :
70
- return False
71
-
72
-
73
- def _skip_if_cant_get_correct_default_credentials ():
74
- if not _check_if_can_get_correct_default_credentials ():
75
- raise nose .SkipTest ("Cannot get default_credentials "
76
- "from the environment!" )
77
-
78
-
79
- def _skip_if_can_get_correct_default_credentials ():
80
- if _check_if_can_get_correct_default_credentials ():
81
- raise nose .SkipTest ("Can get default_credentials "
82
- "from the environment!" )
83
-
84
-
85
59
def _test_imports ():
86
60
global _GOOGLE_API_CLIENT_INSTALLED , _GOOGLE_API_CLIENT_VALID_VERSION , \
87
61
_HTTPLIB2_INSTALLED , _SETUPTOOLS_INSTALLED
@@ -178,6 +152,36 @@ def test_requirements():
178
152
raise nose .SkipTest (import_exception )
179
153
180
154
155
+ def _check_if_can_get_correct_default_credentials ():
156
+ test_requirements ()
157
+ from oauth2client .client import GoogleCredentials
158
+ try :
159
+ from googleapiclient .discovery import build
160
+ except ImportError :
161
+ from apiclient .discovery import build
162
+ try :
163
+ credentials = GoogleCredentials .get_application_default ()
164
+ bigquery_service = build ('bigquery' , 'v2' , credentials = credentials )
165
+ jobs = bigquery_service .jobs ()
166
+ job_data = {'configuration' : {'query' : {'query' : 'SELECT 1' }}}
167
+ jobs .insert (projectId = PROJECT_ID , body = job_data ).execute ()
168
+ return True
169
+ except :
170
+ return False
171
+
172
+
173
+ def _skip_if_cant_get_correct_default_credentials ():
174
+ if not _check_if_can_get_correct_default_credentials ():
175
+ raise nose .SkipTest ("Cannot get default_credentials "
176
+ "from the environment!" )
177
+
178
+
179
+ def _skip_if_can_get_correct_default_credentials ():
180
+ if _check_if_can_get_correct_default_credentials ():
181
+ raise nose .SkipTest ("Can get default_credentials "
182
+ "from the environment!" )
183
+
184
+
181
185
def clean_gbq_environment (private_key = None ):
182
186
dataset = gbq ._Dataset (PROJECT_ID , private_key = private_key )
183
187
0 commit comments