Skip to content

Commit

Permalink
Test resolved fsspec instance
Browse files Browse the repository at this point in the history
  • Loading branch information
steinitzu committed May 22, 2024
1 parent 1ee571b commit d8fc215
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 0 additions & 4 deletions dlt/common/configuration/specs/azure_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
CredentialsWithDefault,
configspec,
)
from dlt.common.configuration.specs.exceptions import InvalidBoto3Session
from dlt import version

import fsspec


@configspec
Expand Down
15 changes: 14 additions & 1 deletion tests/load/filesystem/test_azure_credentials.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Dict
from urllib.parse import parse_qs
from uuid import uuid4

import pytest

Expand All @@ -15,6 +16,7 @@
from tests.load.utils import ALL_FILESYSTEM_DRIVERS
from tests.common.configuration.utils import environment
from tests.utils import preserve_environ, autouse_test_storage
from dlt.common.storages.fsspec_filesystem import fsspec_from_config

# mark all tests as essential, do not remove
pytestmark = pytest.mark.essential
Expand Down Expand Up @@ -130,14 +132,20 @@ def test_azure_filesystem_configuration_service_principal(environment: Dict[str,
environment["CREDENTIALS__AZURE_STORAGE_ACCOUNT_NAME"] = "fake_account_name"
environment["CREDENTIALS__AZURE_CLIENT_ID"] = "fake_client_id"
environment["CREDENTIALS__AZURE_CLIENT_SECRET"] = "asdsadas"
environment["CREDENTIALS__AZURE_TENANT_ID"] = "fake_tenant_id"
environment["CREDENTIALS__AZURE_TENANT_ID"] = str(uuid4())

config = FilesystemConfiguration(bucket_url="az://my-bucket")

resolved_config = resolve_configuration(config)

assert isinstance(resolved_config.credentials, AzureServicePrincipalCredentialsWithoutDefaults)

fs, bucket = fsspec_from_config(resolved_config)

assert fs.tenant_id == environment["CREDENTIALS__AZURE_TENANT_ID"]
assert fs.client_id == environment["CREDENTIALS__AZURE_CLIENT_ID"]
assert fs.client_secret == environment["CREDENTIALS__AZURE_CLIENT_SECRET"]


def test_azure_filesystem_configuration_sas_token(environment: Dict[str, str]) -> None:
environment["CREDENTIALS__AZURE_STORAGE_ACCOUNT_NAME"] = "fake_account_name"
Expand All @@ -150,3 +158,8 @@ def test_azure_filesystem_configuration_sas_token(environment: Dict[str, str]) -
resolved_config = resolve_configuration(config)

assert isinstance(resolved_config.credentials, AzureCredentialsWithoutDefaults)

fs, bucket = fsspec_from_config(resolved_config)

assert fs.sas_token == "?" + environment["CREDENTIALS__AZURE_STORAGE_SAS_TOKEN"]
assert fs.account_name == environment["CREDENTIALS__AZURE_STORAGE_ACCOUNT_NAME"]

0 comments on commit d8fc215

Please sign in to comment.