Skip to content

Commit

Permalink
Tests edited
Browse files Browse the repository at this point in the history
Tests edited to cover the fact that Azure can't give subdirectories.
  • Loading branch information
Frodothedwarf committed May 28, 2024
1 parent 5a74775 commit a015c79
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 41 deletions.
8 changes: 1 addition & 7 deletions storages/backends/azure_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,7 @@ def get_available_name(self, name, max_length=_AZURE_NAME_MAX_LEN):

def exists(self, name):
if not name:
try:
self.service_client.get_container_client(
self.azure_container
)
return True
except:
return False
return True

blob_client = self.client.get_blob_client(self._get_valid_path(name))
return blob_client.exists()
Expand Down
37 changes: 3 additions & 34 deletions tests/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,46 +388,15 @@ def test_storage_listdir_base(self):
)
self.storage._custom_client.list_blobs.assert_not_called()

self.assertEqual(len(dirs), 2)
for directory in ["some", "other"]:
self.assertTrue(
directory in dirs,
""" "{}" not in directory list "{}".""".format(directory, dirs),
)
self.assertEqual(len(dirs), 0)

self.assertEqual(len(files), 2)
for filename in ["2.txt", "4.txt"]:
self.assertEqual(len(files), 4)
for filename in ["2.txt", "4.txt", "other/path/3.txt", "some/path/1.txt"]:
self.assertTrue(
filename in files,
""" "{}" not in file list "{}".""".format(filename, files),
)

def test_storage_listdir_subdir(self):
file_names = ["some/path/1.txt", "some/2.txt"]

result = []
for p in file_names:
obj = mock.MagicMock()
obj.name = p
result.append(obj)
self.storage._client.list_blobs.return_value = iter(result)
self.storage._custom_client.list_blobs.assert_not_called()

dirs, files = self.storage.listdir("some/")
self.storage._client.list_blobs.assert_called_with(
name_starts_with="some/", timeout=20
)

self.assertEqual(len(dirs), 1)
self.assertTrue(
"path" in dirs, """ "path" not in directory list "{}".""".format(dirs)
)

self.assertEqual(len(files), 1)
self.assertTrue(
"2.txt" in files, """ "2.txt" not in files list "{}".""".format(files)
)

def test_size_of_file(self):
props = BlobProperties()
props.size = 12
Expand Down

0 comments on commit a015c79

Please sign in to comment.