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 @@ -3,6 +3,8 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information +from typing import Any, Dict + from django.http import HttpResponse from django.shortcuts import redirect from django.views.decorators.cache import never_cache @@ -41,6 +43,17 @@ ) +def _vault_response(vault_response: Dict[str, Any]) -> Dict[str, Any]: + return { + "fetch_url": vault_response["fetch_url"], + "obj_type": vault_response["type"], + "progress_message": vault_response["progress_msg"], + "id": vault_response["task_id"], + "status": vault_response["task_status"], + "obj_id": vault_response["object_id"], + } + + @never_cache @api_route( r"/vault/directory/(?P[0-9a-f]+)/", @@ -101,9 +114,9 @@ res = _dispatch_cook_progress(request, "directory", obj_id) res["fetch_url"] = reverse( - "api-1-vault-fetch-directory", url_args={"dir_id": dir_id} + "api-1-vault-fetch-directory", url_args={"dir_id": dir_id}, request=request, ) - return res + return _vault_response(res) @api_route( @@ -208,9 +221,11 @@ res = _dispatch_cook_progress(request, "revision_gitfast", obj_id) res["fetch_url"] = reverse( - "api-1-vault-fetch-revision_gitfast", url_args={"rev_id": rev_id} + "api-1-vault-fetch-revision_gitfast", + url_args={"rev_id": rev_id}, + request=request, ) - return res + return _vault_response(res) @api_route( 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 @@ -35,12 +35,11 @@ f"api-1-vault-fetch-{obj_type}", url_args={f"{obj_type[:3]}_id": obj_id}, ) stub_cook = { - "fetch_url": fetch_url, - "obj_id": obj_id, - "obj_type": obj_type, - "progress_message": None, - "status": "done", - "task_uuid": "de75c902-5ee5-4739-996e-448376a93eff", + "type": obj_type, + "progress_msg": None, + "task_id": 1, + "task_status": "done", + "object_id": obj_id, } stub_fetch = b"content" @@ -55,12 +54,14 @@ ) rv = check_api_post_responses(api_client, url, data=None, status_code=200) - - stub_cook["fetch_url"] = rv.wsgi_request.build_absolute_uri( - stub_cook["fetch_url"] - ) - - assert rv.data == stub_cook + assert rv.data == { + "fetch_url": rv.wsgi_request.build_absolute_uri(fetch_url), + "obj_type": obj_type, + "progress_message": None, + "id": 1, + "status": "done", + "obj_id": obj_id, + } mock_archive.vault_cook.assert_called_with( obj_type, hashutil.hash_to_bytes(obj_id), email )