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 map_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]+)/", @@ -100,10 +113,7 @@ ) res = _dispatch_cook_progress(request, "directory", obj_id) - res["fetch_url"] = reverse( - "api-1-vault-fetch-directory", url_args={"dir_id": dir_id} - ) - return res + return map_vault_response(res) @api_route( @@ -207,10 +217,7 @@ ) 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} - ) - return res + return map_vault_response(res) @api_route( diff --git a/swh/web/assets/src/bundles/vault/vault-ui.js b/swh/web/assets/src/bundles/vault/vault-ui.js --- a/swh/web/assets/src/bundles/vault/vault-ui.js +++ b/swh/web/assets/src/bundles/vault/vault-ui.js @@ -193,7 +193,9 @@ localStorage.setItem('swh-vault-cooking-tasks', JSON.stringify(vaultCookingTasks)); checkVaultId = setTimeout(checkVaultCookingTasks, pollingInterval); }) - .catch(() => {}); + .catch(error => { + console.log('Error when fetching vault cooking tasks:', error); + }); } export function removeCookingTaskInfo(tasksToRemove) { 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 @@ -36,11 +36,11 @@ ) 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" @@ -54,13 +54,17 @@ query_params={"email": email}, ) - 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"] - ) + expected_data = { + "fetch_url": fetch_url, + "obj_type": obj_type, + "progress_message": None, + "id": 1, + "status": "done", + "obj_id": obj_id, + } - assert rv.data == stub_cook + rv = check_api_post_responses(api_client, url, data=None, status_code=200) + assert rv.data == expected_data mock_archive.vault_cook.assert_called_with( obj_type, hashutil.hash_to_bytes(obj_id), email )