Skip to content

Commit 72dd843

Browse files
[ENG-11354] WB: Unit tests - Part 1 (#485)
Add minimal metadata fixture and update OSFStorageProvider to handle minimal parameter
1 parent d48e70f commit 72dd843

4 files changed

Lines changed: 57 additions & 8 deletions

File tree

tests/providers/osfstorage/fixtures.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def folder_children_metadata():
9595
with open(os.path.join(os.path.dirname(__file__), 'fixtures/root_provider.json')) as fp:
9696
return json.load(fp)['folder_children_metadata']
9797

98+
@pytest.fixture
99+
def folder_children_metadata_minimal():
100+
with open(os.path.join(os.path.dirname(__file__), 'fixtures/root_provider.json')) as fp:
101+
return json.load(fp)['folder_children_metadata_minimal']
102+
98103

99104
@pytest.fixture
100105
def download_response():

tests/providers/osfstorage/fixtures/root_provider.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@
6666
"latestVersionSeen": null
6767
}
6868
],
69+
"folder_children_metadata_minimal": [
70+
{
71+
"id": "59c0054cb7d1c90114c456af",
72+
"kind": "folder",
73+
"name": "New Folder",
74+
"path": "/59c0054cb7d1c90114c456af/"
75+
},
76+
{
77+
"id": "59a9b637b7d1c903ab5a8f58",
78+
"kind": "file",
79+
"name": "one",
80+
"path": "/59a9b637b7d1c903ab5a8f58"
81+
},
82+
{
83+
"id": "59a9b628b7d1c903ab5a8f52",
84+
"kind": "file",
85+
"name": "doc.rst",
86+
"path": "/59a9b628b7d1c903ab5a8f52"
87+
},
88+
{
89+
"id": "59a5adb9b7d1c901cd40f0e9",
90+
"kind": "file",
91+
"name": "video.mp4",
92+
"path": "/59a5adb9b7d1c901cd40f0e9"
93+
}
94+
],
6995
"file_metadata": {
7096
"checkout": null,
7197
"contentType": null,

tests/providers/osfstorage/test_provider.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
file_lineage, file_metadata,
2525
file_metadata_object, file_path,
2626
folder_lineage, folder_metadata,
27-
folder_children_metadata, folder_path,
27+
folder_children_metadata, folder_children_metadata_minimal, folder_path,
2828
revisions_metadata, revision_metadata_object,
2929
download_response, download_path,
3030
upload_response, upload_path, root_path,
@@ -210,7 +210,7 @@ async def test_delete_folder_contents(self, provider_one, file_path, folder_path
210210

211211
children_url, params = build_signed_url_without_auth(provider_one, 'GET',
212212
folder_path.identifier, 'children',
213-
user_id=provider_one.auth['id'])
213+
user_id=provider_one.auth['id'], minimal=False)
214214
aiohttpretty.register_json_uri('GET', children_url, params=params, status=200,
215215
body=folder_children_metadata)
216216

@@ -227,7 +227,7 @@ class TestMetadata:
227227
async def test_provider_metadata_empty(self, provider_one, folder_path, mock_time):
228228

229229
url, params = build_signed_url_without_auth(provider_one, 'GET', folder_path.identifier,
230-
'children', user_id=provider_one.auth['id'])
230+
'children', user_id=provider_one.auth['id'], minimal=False)
231231
aiohttpretty.register_json_uri('GET', url, params=params, status_code=200, body=[])
232232

233233
res = await provider_one.metadata(folder_path)
@@ -241,7 +241,7 @@ async def test_provider_metadata_folder(self, provider_one, folder_path,
241241
folder_children_metadata, mock_time):
242242

243243
url, params = build_signed_url_without_auth(provider_one, 'GET', folder_path.identifier,
244-
'children', user_id=provider_one.auth['id'])
244+
'children', user_id=provider_one.auth['id'], minimal=False)
245245
aiohttpretty.register_json_uri('GET', url, params=params, status=200,
246246
body=folder_children_metadata)
247247

@@ -276,7 +276,7 @@ async def test_provider_metadata_without_id(self, provider_one, folder_path,
276276
folder_children_metadata, mock_time):
277277

278278
url, params = build_signed_url_without_auth(provider_one, 'GET', folder_path.identifier,
279-
'children')
279+
'children', minimal=False)
280280
aiohttpretty.register_json_uri('GET', url, params=params, status=200,
281281
body=folder_children_metadata)
282282
folder_path._parts[-1]._id = None
@@ -732,7 +732,7 @@ async def test_validate_path_404s(self, provider_one, file_lineage, mock_time):
732732
async def test_revalidate_path_new(self, provider_one, folder_path, folder_children_metadata,
733733
mock_time):
734734
url, params = build_signed_url_without_auth(provider_one, 'GET', folder_path.identifier,
735-
'children', user_id=provider_one.auth['id'])
735+
'children', user_id=provider_one.auth['id'], minimal=False)
736736
aiohttpretty.register_json_uri('GET', url, params=params, status=200,
737737
body=folder_children_metadata)
738738

@@ -745,7 +745,7 @@ async def test_revalidate_path_new(self, provider_one, folder_path, folder_child
745745
async def test_revalidate_path_existing(self, provider_one, folder_path,
746746
folder_children_metadata, mock_time):
747747
url, params = build_signed_url_without_auth(provider_one, 'GET', folder_path.identifier,
748-
'children', user_id=provider_one.auth['id'])
748+
'children', user_id=provider_one.auth['id'], minimal=False)
749749
aiohttpretty.register_json_uri('GET', url, params=params, status=200,
750750
body=folder_children_metadata)
751751

@@ -1253,3 +1253,21 @@ async def test_intra_copy_reject_by_quota(self, provider_one, auth, credentials,
12531253
src_provider.can_intra_copy.assert_called_once_with(dst_provider, src_path)
12541254
src_provider.intra_copy.assert_not_called()
12551255
src_provider.download.assert_not_called()
1256+
1257+
class TestMinimalMetadataDAZ:
1258+
1259+
@pytest.mark.asyncio
1260+
@pytest.mark.aiohttpretty
1261+
async def test_minimal_metadata(self, provider_one, folder_path, folder_children_metadata_minimal):
1262+
1263+
url, params = build_signed_url_without_auth(provider_one, 'GET', folder_path.identifier,
1264+
'children', user_id=provider_one.auth['id'], minimal=True)
1265+
aiohttpretty.register_json_uri('GET', url, params=params, status=200,
1266+
body=folder_children_metadata_minimal)
1267+
1268+
metadata = await provider_one.metadata(folder_path, minimal=True)
1269+
1270+
assert [type(metadata_item) for metadata_item in metadata] == [OsfStorageFolderMetadata, OsfStorageFileMetadata, OsfStorageFileMetadata, OsfStorageFileMetadata]
1271+
assert [metadata_item.name for metadata_item in metadata] == ['New Folder', 'one', 'doc.rst', 'video.mp4']
1272+
assert [metadata_item.path for metadata_item in metadata] == ['/59c0054cb7d1c90114c456af/', '/59a9b637b7d1c903ab5a8f58', '/59a9b628b7d1c903ab5a8f52', '/59a5adb9b7d1c901cd40f0e9']
1273+
assert [metadata_item.provider for metadata_item in metadata] == ['osfstorage', 'osfstorage', 'osfstorage', 'osfstorage']

waterbutler/providers/osfstorage/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ async def _item_metadata(self, path, revision=None):
532532
async def _children_metadata(self, path, **kwargs):
533533
resp = await self.make_signed_request(
534534
'GET',
535-
self.build_url(path.identifier, 'children', user_id=self.auth.get('id'), minimal=kwargs.get('minimal')),
535+
self.build_url(path.identifier, 'children', user_id=self.auth.get('id'), minimal=kwargs.get('minimal', False)),
536536
expects=(200, )
537537
)
538538
resp_json = await resp.json()

0 commit comments

Comments
 (0)