diff --git a/swh/web/api/views/vault.py b/swh/web/api/views/vault.py --- a/swh/web/api/views/vault.py +++ b/swh/web/api/views/vault.py @@ -53,13 +53,12 @@ "progress_message": vault_response["progress_msg"], "id": vault_response["task_id"], "status": vault_response["task_status"], - "swhid": vault_response["swhid"], + "swhid": str(vault_response["swhid"]), } if add_legacy_items: - swhid = CoreSWHID.from_string(vault_response["swhid"]) - d["obj_type"] = swhid.object_type.name.lower() - d["obj_id"] = hash_to_hex(swhid.object_id) + d["obj_type"] = vault_response["swhid"].object_type.name.lower() + d["obj_id"] = hash_to_hex(vault_response["swhid"].object_id) return d diff --git a/swh/web/tests/api/views/test_vault.py b/swh/web/tests/api/views/test_vault.py --- a/swh/web/tests/api/views/test_vault.py +++ b/swh/web/tests/api/views/test_vault.py @@ -37,10 +37,11 @@ ("gitfast", f"swh:1:rev:{revision}", "application/gzip"), ("git_bare", f"swh:1:rev:{revision}", "application/x-tar"), ): + swhid = CoreSWHID.from_string(swhid) fetch_url = reverse( f"api-1-vault-fetch-{bundle_type.replace('_', '-')}", - url_args={"swhid": swhid}, + url_args={"swhid": str(swhid)}, ) stub_cook = { "type": bundle_type, @@ -57,7 +58,7 @@ email = "test@test.mail" url = reverse( f"api-1-vault-cook-{bundle_type.replace('_', '-')}", - url_args={"swhid": swhid}, + url_args={"swhid": str(swhid)}, query_params={"email": email}, ) @@ -67,18 +68,14 @@ "progress_message": None, "id": 1, "status": "done", - "swhid": swhid, + "swhid": str(swhid), } - mock_archive.vault_cook.assert_called_with( - bundle_type, CoreSWHID.from_string(swhid), email - ) + mock_archive.vault_cook.assert_called_with(bundle_type, swhid, email) rv = check_http_get_response(api_client, fetch_url, status_code=200) assert rv["Content-Type"] == content_type assert rv.content == stub_fetch - mock_archive.vault_fetch.assert_called_with( - bundle_type, CoreSWHID.from_string(swhid) - ) + mock_archive.vault_fetch.assert_called_with(bundle_type, swhid) @given(directory(), revision(), unknown_directory(), unknown_revision()) @@ -95,46 +92,44 @@ ("gitfast", f"swh:1:rev:{revision}"), ("git_bare", f"swh:1:rev:{revision}"), ): + swhid = CoreSWHID.from_string(swhid) url = reverse( f"api-1-vault-cook-{bundle_type.replace('_', '-')}", - url_args={"swhid": swhid}, + url_args={"swhid": str(swhid)}, ) rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data["exception"] == "NotFoundExc" assert rv.data["reason"] == f"Cooking of {swhid} was never requested." - mock_vault.progress.assert_called_with( - bundle_type, CoreSWHID.from_string(swhid) - ) + mock_vault.progress.assert_called_with(bundle_type, swhid) for bundle_type, swhid in ( ("flat", f"swh:1:dir:{unknown_directory}"), ("gitfast", f"swh:1:rev:{unknown_revision}"), ("git_bare", f"swh:1:rev:{unknown_revision}"), ): + swhid = CoreSWHID.from_string(swhid) url = reverse( f"api-1-vault-cook-{bundle_type.replace('_', '-')}", - url_args={"swhid": swhid}, + url_args={"swhid": str(swhid)}, ) rv = check_api_post_responses(api_client, url, data=None, status_code=404) assert rv.data["exception"] == "NotFoundExc" assert rv.data["reason"] == f"{swhid} not found." - mock_vault.cook.assert_called_with( - bundle_type, CoreSWHID.from_string(swhid), email=None - ) + mock_vault.cook.assert_called_with(bundle_type, swhid, email=None) fetch_url = reverse( f"api-1-vault-fetch-{bundle_type.replace('_', '-')}", - url_args={"swhid": swhid}, + url_args={"swhid": str(swhid)}, ) rv = check_api_get_responses(api_client, fetch_url, status_code=404) assert rv.data["exception"] == "NotFoundExc" assert rv.data["reason"] == f"Cooked archive for {swhid} not found." - mock_vault.fetch.assert_called_with(bundle_type, CoreSWHID.from_string(swhid)) + mock_vault.fetch.assert_called_with(bundle_type, swhid) @pytest.mark.parametrize("bundle_type", ["flat", "gitfast", "git_bare"]) @@ -204,10 +199,10 @@ ("directory", "flat", "directory", directory), ("revision_gitfast", "gitfast", "revision", revision), ): - swhid = f"swh:1:{obj_type[:3]}:{obj_id}" + swhid = CoreSWHID.from_string(f"swh:1:{obj_type[:3]}:{obj_id}") fetch_url = reverse( - f"api-1-vault-fetch-{bundle_type}", url_args={"swhid": swhid}, + f"api-1-vault-fetch-{bundle_type}", url_args={"swhid": str(swhid)}, ) stub_cook = { "type": obj_type, @@ -236,20 +231,16 @@ "progress_message": None, "id": 1, "status": "done", - "swhid": swhid, + "swhid": str(swhid), "obj_type": response_obj_type, "obj_id": obj_id, } - mock_archive.vault_cook.assert_called_with( - bundle_type, CoreSWHID.from_string(swhid), email - ) + mock_archive.vault_cook.assert_called_with(bundle_type, swhid, email) rv = check_http_get_response(api_client, fetch_url, status_code=200) assert rv["Content-Type"] == "application/gzip" assert rv.content == stub_fetch - mock_archive.vault_fetch.assert_called_with( - bundle_type, CoreSWHID.from_string(swhid) - ) + mock_archive.vault_fetch.assert_called_with(bundle_type, swhid) @given(directory(), revision()) @@ -306,21 +297,19 @@ f"api-1-vault-cook-{obj_type}", url_args={f"{obj_type[:3]}_id": obj_id}, ) - swhid = f"swh:1:{obj_type[:3]}:{obj_id}" + swhid = CoreSWHID.from_string(f"swh:1:{obj_type[:3]}:{obj_id}") rv = check_api_get_responses(api_client, url, status_code=404) assert rv.data["exception"] == "NotFoundExc" assert rv.data["reason"] == f"Cooking of {swhid} was never requested." - mock_vault.progress.assert_called_with( - bundle_type, CoreSWHID.from_string(swhid) - ) + mock_vault.progress.assert_called_with(bundle_type, swhid) for obj_type, bundle_type, obj_id in ( ("directory", "flat", unknown_directory), ("revision_gitfast", "gitfast", unknown_revision), ): - swhid = f"swh:1:{obj_type[:3]}:{obj_id}" + swhid = CoreSWHID.from_string(f"swh:1:{obj_type[:3]}:{obj_id}") url = reverse( f"api-1-vault-cook-{obj_type}", url_args={f"{obj_type[:3]}_id": obj_id} @@ -329,9 +318,7 @@ assert rv.data["exception"] == "NotFoundExc" assert rv.data["reason"] == f"{swhid} not found." - mock_vault.cook.assert_called_with( - bundle_type, CoreSWHID.from_string(swhid), email=None - ) + mock_vault.cook.assert_called_with(bundle_type, swhid, email=None) fetch_url = reverse( f"api-1-vault-fetch-{obj_type}", url_args={f"{obj_type[:3]}_id": obj_id}, @@ -340,11 +327,11 @@ # Redirected to the current 'fetch' url rv = check_http_get_response(api_client, fetch_url, status_code=302) redirect_url = reverse( - f"api-1-vault-fetch-{bundle_type}", url_args={"swhid": swhid}, + f"api-1-vault-fetch-{bundle_type}", url_args={"swhid": str(swhid)}, ) assert rv["location"] == redirect_url rv = check_api_get_responses(api_client, redirect_url, status_code=404) assert rv.data["exception"] == "NotFoundExc" assert rv.data["reason"] == f"Cooked archive for {swhid} not found." - mock_vault.fetch.assert_called_with(bundle_type, CoreSWHID.from_string(swhid)) + mock_vault.fetch.assert_called_with(bundle_type, swhid)