Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Azure api tests #1913

Merged
merged 4 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_key(self, key_name):


@fixture
def mock_blob_client(monkeypatch): # noqa: ARG001
def mock_blob_client(monkeypatch):
class MockBlobClient:
def __init__(
self,
Expand All @@ -42,6 +42,24 @@ def exists(self):
else:
return False

def mock_blob_client(
self, # noqa: ARG001
resource_group_name,
storage_account_name,
storage_container_name,
blob_name,
):
return MockBlobClient(
resource_group_name,
storage_account_name,
storage_container_name,
blob_name,
)

monkeypatch.setattr(
data_safe_haven.external.api.azure_api.AzureApi, "blob_client", mock_blob_client
)


class TestAzureApi:
def test_get_keyvault_key(self, mock_key_client): # noqa: ARG002
Expand All @@ -58,12 +76,16 @@ def test_get_keyvault_key_missing(self, mock_key_client): # noqa: ARG002

def test_blob_exists(self, mock_blob_client): # noqa: ARG002
api = AzureApi("subscription name")
assert api.blob_exists(
"resource_group", "storage_account", "storage_container", "exists"
exists = api.blob_exists(
"exists", "resource_group", "storage_account", "storage_container"
)
assert isinstance(exists, bool)
assert exists

def test_blob_does_not_exist(self, mock_blob_client): # noqa: ARG002
api = AzureApi("subscription name")
assert not api.blob_exists(
"resource_group", "storage_account", "storage_container", "abc.txt"
exists = api.blob_exists(
"abc.txt", "resource_group", "storage_account", "storage_container"
)
assert isinstance(exists, bool)
assert not exists
Loading