-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from statisticsnorway/auth-gcs-file-system
Use ADC for GCSFileSystem when applicable
- Loading branch information
Showing
7 changed files
with
23 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "dapla-toolbelt" | ||
version = "3.2.0" | ||
version = "3.2.1" | ||
description = "Dapla Toolbelt" | ||
authors = ["Dapla Developers <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -52,7 +52,7 @@ pytest = ">=7.1.2" | |
responses = ">=0.24.0" | ||
types-requests = ">=2.28.11" | ||
pyarrow-stubs = ">=10.0.1.7" | ||
google-auth-stubs = ">=0.2.0" # Not maintained by Google, should change if Google releases their own stubs | ||
google-auth-stubs = ">=0.2.0" # Not maintained by Google, should change if Google releases their own stubs | ||
pandas-stubs = ">=2.0.0" | ||
pytest-timeout = ">=2.3.1" | ||
pytest-mock = ">=3.14.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,7 @@ | ||
from datetime import timedelta | ||
from unittest.mock import Mock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from gcsfs.retry import HttpError | ||
from google.auth._helpers import utcnow | ||
|
||
from dapla import pandas as dp | ||
from dapla.gcs import GCSFileSystem | ||
|
||
|
||
def test_instance() -> None: | ||
# Chack that instantiation works with the current version of pyarrow | ||
client = GCSFileSystem() | ||
assert client is not None | ||
|
||
|
||
@pytest.mark.timeout( | ||
30 | ||
) # Times the test out after 30 sec, this is will happen if a deadlock happens | ||
@patch.dict("dapla.auth.os.environ", {"OIDC_TOKEN": "fake-token"}, clear=True) | ||
@patch.dict( | ||
"dapla.auth.os.environ", {"DAPLA_TOOLBELT_FORCE_TOKEN_EXCHANGE": "1"}, clear=True | ||
) | ||
@patch("dapla.auth.AuthClient.fetch_google_token") | ||
def test_gcs_deadlock(mock_fetch_google_token: Mock) -> None: | ||
# When overriding the refresh method we experienced a deadlock, resulting in the credentials never being refreshed | ||
# This test checks that the credentials object is updated on refresh | ||
# and that it proceeds to the next step when a valid token is provided. | ||
|
||
mock_fetch_google_token.side_effect = [ | ||
("FakeToken1", utcnow()), | ||
("FakeToken2", utcnow()), | ||
("FakeToken3", utcnow()), | ||
("FakeToken4", utcnow()), | ||
("FakeToken5Valid", utcnow() + timedelta(seconds=30)), | ||
] | ||
|
||
gcs_path = "gs://ssb-dapla-pseudo-data-produkt-test/integration_tests_data/personer.parquet" | ||
with pytest.raises( | ||
HttpError | ||
) as exc_info: # Since we supply invalid credentials an error should be raised | ||
dp.read_pandas(gcs_path) | ||
assert "Invalid Credentials" in str(exc_info.value) | ||
assert ( | ||
mock_fetch_google_token.call_count == 5 | ||
) # mock_fetch_google_token is called as part of refresh | ||
# until a token that has not expired is returned |