Skip to content

Commit cf41e76

Browse files
committed
modified documentation + restructured tests
1 parent 62815e1 commit cf41e76

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

doc/source/io.rst

+9
Original file line numberDiff line numberDiff line change
@@ -4475,6 +4475,15 @@ Additional information on service accounts can be found
44754475

44764476
You will need to install an additional dependency: `oauth2client <https://github.com/google/oauth2client>`__.
44774477

4478+
.. versionadded:: 0.19.0
4479+
4480+
Authentication via ``application default credentials`` is also possible. This is only valid
4481+
if the parameter ``private_key`` is not provided. This method also requires that
4482+
the credentials can be fetched from the environment the code is running in.
4483+
Otherwise, the OAuth2 client-side authentication is used.
4484+
Additional information on ``application default credentials`` can be found
4485+
`here <https://developers.google.com/identity/protocols/application-default-credentials>`__.
4486+
44784487
.. note::
44794488

44804489
The `'private_key'` parameter can be set to either the file path of the service account key

doc/source/whatsnew/v0.19.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Google BigQuery Enhancements
361361
Other enhancements
362362
^^^^^^^^^^^^^^^^^^
363363

364-
- The ``.get_credentials()`` method of ``GbqConnector`` can now first try to fetch the application default credentials (https://developers.google.com/identity/protocols/application-default-credentials). This is only valid if the parameter ``private_key`` is not provided. Using this functionality, the ``OAuth2WebServerFlow`` call can be skipped (:issue:`13577`).
364+
- The ``.get_credentials()`` method of ``GbqConnector`` can now first try to fetch [the application default credentials](https://developers.google.com/identity/protocols/application-default-credentials). This is only valid if the parameter ``private_key`` is not provided. Using this functionality, the ``OAuth2WebServerFlow`` call can be skipped (:issue:`13577`).
365365

366366
- The ``.tz_localize()`` method of ``DatetimeIndex`` and ``Timestamp`` has gained the ``errors`` keyword, so you can potentially coerce nonexistent timestamps to ``NaT``. The default behaviour remains to raising a ``NonExistentTimeError`` (:issue:`13057`)
367367
- ``pd.to_numeric()`` now accepts a ``downcast`` parameter, which will downcast the data if possible to smallest specified numerical dtype (:issue:`13352`)

pandas/io/tests/test_gbq.py

+9-14
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ def test_requirements():
153153

154154

155155
def _check_if_can_get_correct_default_credentials():
156+
# Checks if "Application Default Credentials" can be fetched
157+
# from the environment the tests are running in.
158+
# See Issue #13577
156159
test_requirements()
157160
from oauth2client.client import GoogleCredentials
158161
try:
@@ -170,18 +173,6 @@ def _check_if_can_get_correct_default_credentials():
170173
return False
171174

172175

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-
185176
def clean_gbq_environment(private_key=None):
186177
dataset = gbq._Dataset(PROJECT_ID, private_key=private_key)
187178

@@ -249,12 +240,16 @@ def test_should_be_able_to_get_results_from_query(self):
249240
self.assertTrue(pages is not None)
250241

251242
def test_get_application_default_credentials_does_not_throw_error(self):
252-
_skip_if_can_get_correct_default_credentials()
243+
if _check_if_can_get_correct_default_credentials():
244+
raise nose.SkipTest("Can get default_credentials "
245+
"from the environment!")
253246
credentials = self.sut.get_application_default_credentials()
254247
self.assertIsNone(credentials)
255248

256249
def test_get_application_default_credentials_returns_credentials(self):
257-
_skip_if_cant_get_correct_default_credentials()
250+
if not _check_if_can_get_correct_default_credentials():
251+
raise nose.SkipTest("Cannot get default_credentials "
252+
"from the environment!")
258253
from oauth2client.client import GoogleCredentials
259254
credentials = self.sut.get_application_default_credentials()
260255
self.assertTrue(isinstance(credentials, GoogleCredentials))

0 commit comments

Comments
 (0)