Skip to content

Commit

Permalink
[azure] Add non-regression test case for writable URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinGoodays committed Jul 3, 2024
1 parent 20a5c86 commit 8f894f1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def test_url_expire(self, generate_blob_sas_mocked):
fixed_time = make_aware(
datetime.datetime(2016, 11, 6, 4), datetime.timezone.utc
)

with mock.patch("storages.backends.azure_storage.datetime") as d_mocked:

# Implicit read permission
d_mocked.utcnow.return_value = fixed_time
self.assertEqual(
self.storage.url("some blob", 100),
Expand All @@ -179,6 +182,26 @@ def test_url_expire(self, generate_blob_sas_mocked):
permission=mock.ANY,
expiry=fixed_time + timedelta(seconds=100),
)
called_args, called_kwargs = generate_blob_sas_mocked.call_args
self.assertEqual(str(called_kwargs["permission"]), "r")

# Explicit write permission
d_mocked.utcnow.return_value = fixed_time
self.assertEqual(
self.storage.url("some blob", expire=100, mode="w"),
"https://ret_foo.blob.core.windows.net/test/some%20blob",
)
generate_blob_sas_mocked.assert_called_with(
self.account_name,
self.container_name,
"some blob",
account_key=self.account_key,
user_delegation_key=None,
permission=mock.ANY,
expiry=fixed_time + timedelta(seconds=100),
)
called_args, called_kwargs = generate_blob_sas_mocked.call_args
self.assertEqual(str(called_kwargs["permission"]), "w")

@mock.patch("storages.backends.azure_storage.generate_blob_sas")
def test_url_expire_user_delegation_key(self, generate_blob_sas_mocked):
Expand Down

0 comments on commit 8f894f1

Please sign in to comment.