|
21 | 21 | from test import reset_tweak_changes, TEST_DIR |
22 | 22 |
|
23 | 23 |
|
| 24 | +def get_uploaded_file_names(path: str): |
| 25 | + files = [] |
| 26 | + for entry in os.scandir(path=path): |
| 27 | + if entry.is_file(): |
| 28 | + files.append(entry.name) |
| 29 | + if entry.is_dir(): |
| 30 | + nested_files = get_uploaded_file_names(entry.path) |
| 31 | + for file in nested_files: |
| 32 | + files.append('{}/{}'.format(entry.name, file)) |
| 33 | + return files |
| 34 | + |
| 35 | + |
24 | 36 | class TestDssApi(unittest.TestCase): |
25 | 37 | staging_bucket = "org-humancellatlas-dss-cli-test" |
26 | 38 |
|
@@ -71,9 +83,31 @@ def test_python_nested_bundle_upload_download(self): |
71 | 83 | downloaded_file_paths = [object_name_builder(p, dest_dir) for p in downloaded_file_names] |
72 | 84 | self.assertEqual(uploaded_files.sort(), downloaded_file_paths.sort()) |
73 | 85 |
|
| 86 | + @unittest.skipIf(os.name is 'nt', 'Unable to test on Windows') # TODO windows testing refactor |
| 87 | + def test_python_exclamation_replacement(self): |
| 88 | + bundle_path = os.path.join(TEST_DIR, "res", "nested_bundle") |
| 89 | + uploaded_files = set(get_uploaded_file_names(bundle_path)) |
| 90 | + |
| 91 | + bundle_output = self.client.upload(src_dir=bundle_path, |
| 92 | + replica="aws", |
| 93 | + staging_bucket=self.staging_bucket) |
| 94 | + |
| 95 | + bundle_uuid = bundle_output['bundle_uuid'] |
| 96 | + bundle_version = bundle_output['version'] |
| 97 | + bundle_fqid = "{}.{}".format(bundle_uuid, bundle_version) |
| 98 | + |
| 99 | + manifest_files = bundle_output['files'] |
| 100 | + self.assertEqual({file['name'] for file in manifest_files}, uploaded_files) |
| 101 | + |
| 102 | + with tempfile.TemporaryDirectory() as dest_dir: |
| 103 | + self.client.download(bundle_uuid=bundle_output['bundle_uuid'], replica="aws", download_dir=dest_dir) |
| 104 | + nested_downloaded_files = [file.name for file in os.scandir('{}/{}/zarr'.format(dest_dir, bundle_fqid))] |
| 105 | + for file in ['exclamation.zattrs', 'nested.zattrs']: |
| 106 | + self.assertIn(file, nested_downloaded_files) |
| 107 | + |
74 | 108 | def test_python_upload_download(self): |
75 | 109 | bundle_path = os.path.join(TEST_DIR, "res", "bundle") |
76 | | - uploaded_files = set(os.listdir(bundle_path)) |
| 110 | + uploaded_files = set(get_uploaded_file_names(bundle_path)) |
77 | 111 |
|
78 | 112 | manifest = self.client.upload(src_dir=bundle_path, |
79 | 113 | replica="aws", |
@@ -139,7 +173,7 @@ def test_python_upload_download(self): |
139 | 173 |
|
140 | 174 | def test_python_manifest_download(self): |
141 | 175 | bundle_path = os.path.join(TEST_DIR, "res", "bundle") |
142 | | - uploaded_files = set(os.listdir(bundle_path)) |
| 176 | + uploaded_files = set(get_uploaded_file_names(bundle_path)) |
143 | 177 |
|
144 | 178 | manifest = self.client.upload(src_dir=bundle_path, |
145 | 179 | replica="aws", |
|
0 commit comments