Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_vault.py
# Copyright (C) 2017-2021 The Software Heritage developers | # Copyright (C) 2017-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import re | import re | ||||
from hypothesis import given | |||||
import pytest | import pytest | ||||
from swh.model.swhids import CoreSWHID | from swh.model.swhids import CoreSWHID | ||||
from swh.vault.exc import NotFoundExc | from swh.vault.exc import NotFoundExc | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import reverse | ||||
from swh.web.tests.strategies import unknown_directory, unknown_revision | |||||
from swh.web.tests.utils import ( | from swh.web.tests.utils import ( | ||||
check_api_get_responses, | check_api_get_responses, | ||||
check_api_post_responses, | check_api_post_responses, | ||||
check_http_get_response, | check_http_get_response, | ||||
check_http_post_response, | check_http_post_response, | ||||
) | ) | ||||
##################### | ##################### | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | ): | ||||
mock_archive.vault_cook.assert_called_with(bundle_type, 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) | rv = check_http_get_response(api_client, fetch_url, status_code=200) | ||||
assert rv["Content-Type"] == content_type | assert rv["Content-Type"] == content_type | ||||
assert rv.content == stub_fetch | assert rv.content == stub_fetch | ||||
mock_archive.vault_fetch.assert_called_with(bundle_type, swhid) | mock_archive.vault_fetch.assert_called_with(bundle_type, swhid) | ||||
@given(unknown_directory(), unknown_revision()) | |||||
def test_api_vault_cook_notfound( | def test_api_vault_cook_notfound( | ||||
api_client, mocker, directory, revision, unknown_directory, unknown_revision | api_client, mocker, directory, revision, unknown_directory, unknown_revision | ||||
): | ): | ||||
mock_vault = mocker.patch("swh.web.common.archive.vault") | mock_vault = mocker.patch("swh.web.common.archive.vault") | ||||
mock_vault.cook.side_effect = NotFoundExc("object not found") | mock_vault.cook.side_effect = NotFoundExc("object not found") | ||||
mock_vault.fetch.side_effect = NotFoundExc("cooked archive not found") | mock_vault.fetch.side_effect = NotFoundExc("cooked archive not found") | ||||
mock_vault.progress.side_effect = NotFoundExc("cooking request not found") | mock_vault.progress.side_effect = NotFoundExc("cooking request not found") | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | ): | ||||
redirect_url = reverse( | redirect_url = reverse( | ||||
f"api-1-vault-fetch-{obj_type}", url_args={f"{obj_type[:3]}_id": obj_id}, | f"api-1-vault-fetch-{obj_type}", url_args={f"{obj_type[:3]}_id": obj_id}, | ||||
) | ) | ||||
assert rv["location"] == redirect_url | assert rv["location"] == redirect_url | ||||
@given(unknown_directory(), unknown_revision()) | |||||
def test_api_vault_cook_notfound_legacy( | def test_api_vault_cook_notfound_legacy( | ||||
api_client, mocker, directory, revision, unknown_directory, unknown_revision | api_client, mocker, directory, revision, unknown_directory, unknown_revision | ||||
): | ): | ||||
mock_vault = mocker.patch("swh.web.common.archive.vault") | mock_vault = mocker.patch("swh.web.common.archive.vault") | ||||
mock_vault.cook.side_effect = NotFoundExc("object not found") | mock_vault.cook.side_effect = NotFoundExc("object not found") | ||||
mock_vault.fetch.side_effect = NotFoundExc("cooked archive not found") | mock_vault.fetch.side_effect = NotFoundExc("cooked archive not found") | ||||
mock_vault.progress.side_effect = NotFoundExc("cooking request not found") | mock_vault.progress.side_effect = NotFoundExc("cooking request not found") | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |