Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_vault.py
Show All 26 Lines | |||||
##################### | ##################### | ||||
# Current API: | # Current API: | ||||
@given(directory(), revision()) | @given(directory(), revision()) | ||||
def test_api_vault_cook(api_client, mocker, directory, revision): | def test_api_vault_cook(api_client, mocker, directory, revision): | ||||
mock_archive = mocker.patch("swh.web.api.views.vault.archive") | mock_archive = mocker.patch("swh.web.api.views.vault.archive") | ||||
for bundle_type, swhid in ( | for bundle_type, swhid, content_type, in ( | ||||
("flat", f"swh:1:dir:{directory}"), | ("flat", f"swh:1:dir:{directory}", "application/gzip"), | ||||
("gitfast", f"swh:1:rev:{revision}"), | ("gitfast", f"swh:1:rev:{revision}", "application/gzip"), | ||||
("git_bare", f"swh:1:rev:{revision}"), | ("git_bare", f"swh:1:rev:{revision}", "application/x-tar"), | ||||
): | ): | ||||
fetch_url = reverse( | fetch_url = reverse( | ||||
f"api-1-vault-fetch-{bundle_type.replace('_', '-')}", | f"api-1-vault-fetch-{bundle_type.replace('_', '-')}", | ||||
url_args={"swhid": swhid}, | url_args={"swhid": swhid}, | ||||
) | ) | ||||
stub_cook = { | stub_cook = { | ||||
"type": bundle_type, | "type": bundle_type, | ||||
Show All 22 Lines | ): | ||||
"status": "done", | "status": "done", | ||||
"swhid": swhid, | "swhid": swhid, | ||||
} | } | ||||
mock_archive.vault_cook.assert_called_with( | mock_archive.vault_cook.assert_called_with( | ||||
bundle_type, CoreSWHID.from_string(swhid), email | bundle_type, CoreSWHID.from_string(swhid), email | ||||
) | ) | ||||
rv = check_http_get_response(api_client, fetch_url, status_code=200) | rv = check_http_get_response(api_client, fetch_url, status_code=200) | ||||
assert rv["Content-Type"] == "application/gzip" | assert rv["Content-Type"] == content_type | ||||
assert rv.content == stub_fetch | assert rv.content == stub_fetch | ||||
mock_archive.vault_fetch.assert_called_with( | mock_archive.vault_fetch.assert_called_with( | ||||
bundle_type, CoreSWHID.from_string(swhid) | bundle_type, CoreSWHID.from_string(swhid) | ||||
) | ) | ||||
@given(directory(), revision(), unknown_directory(), unknown_revision()) | @given(directory(), revision(), unknown_directory(), unknown_revision()) | ||||
def test_api_vault_cook_notfound( | def test_api_vault_cook_notfound( | ||||
▲ Show 20 Lines • Show All 261 Lines • Show Last 20 Lines |