Skip to content

Commit

Permalink
Add tests for initialising Azure filesystem and fix anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Newton committed Sep 23, 2023
1 parent c0ca005 commit aea52be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 1 addition & 2 deletions flytekit/core/data_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def azure_setup_args(azure_cfg: configuration.AzureBlobStorageConfig, anonymous:
if azure_cfg.tenant_id:
kwargs["tenant_id"] = azure_cfg.tenant_id

if anonymous:
kwargs[_ANON] = True
kwargs[_ANON] = anonymous

return kwargs

Expand Down
29 changes: 29 additions & 0 deletions tests/flytekit/unit/core/test_data_persistence.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import os

from azure.identity import ClientSecretCredential, DefaultAzureCredential
from mock import patch
from flytekit.core.data_persistence import FileAccessProvider


Expand All @@ -14,3 +18,28 @@ def test_is_remote():
assert fp.is_remote("/tmp/foo/bar") is False
assert fp.is_remote("file://foo/bar") is False
assert fp.is_remote("s3://my-bucket/foo/bar") is True


def test_initialise_azure_file_provider_with_account_key():
with patch.dict(os.environ, {"FLYTE_AZURE_ACCOUNT_NAME": "accountname", "FLYTE_AZURE_ACCOUNT_KEY": "accountkey"}, clear=True):
fp = FileAccessProvider("/tmp", "abfs://container/path/within/container")
assert fp.get_filesystem().account_name == "accountname"
assert fp.get_filesystem().account_key == "accountkey"
assert fp.get_filesystem().sync_credential is None

def test_initialise_azure_file_provider_with_service_principal():
with patch.dict(os.environ, {"FLYTE_AZURE_ACCOUNT_NAME": "accountname", "FLYTE_AZURE_CLIENT_SECRET": "clientsecret", "FLYTE_AZURE_CLIENT_ID": "clientid",
"FLYTE_AZURE_TENANT_ID": "tenantid"
}, clear=True):
fp = FileAccessProvider("/tmp", "abfs://container/path/within/container")
assert fp.get_filesystem().account_name == "accountname"
assert isinstance(fp.get_filesystem().sync_credential, ClientSecretCredential)
assert fp.get_filesystem().client_secret == "clientsecret"
assert fp.get_filesystem().client_id == "clientid"
assert fp.get_filesystem().tenant_id == "tenantid"

def test_initialise_azure_file_provider_with_default_credential():
with patch.dict(os.environ, {"FLYTE_AZURE_ACCOUNT_NAME": "accountname"}, clear=True):
fp = FileAccessProvider("/tmp", "abfs://container/path/within/container")
assert fp.get_filesystem().account_name == "accountname"
assert isinstance(fp.get_filesystem().sync_credential, DefaultAzureCredential)

0 comments on commit aea52be

Please sign in to comment.