Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_identifiers.py
# Copyright (C) 2018-2021 The Software Heritage developers | # Copyright (C) 2018-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 | ||||
from hypothesis import given | |||||
from swh.model.swhids import ObjectType | from swh.model.swhids import ObjectType | ||||
from swh.web.common.identifiers import gen_swhid | from swh.web.common.identifiers import gen_swhid | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import reverse | ||||
from swh.web.tests.data import random_sha1 | from swh.web.tests.data import random_sha1 | ||||
from swh.web.tests.strategies import ( | |||||
unknown_content, | |||||
unknown_directory, | |||||
unknown_release, | |||||
unknown_revision, | |||||
unknown_snapshot, | |||||
) | |||||
from swh.web.tests.utils import check_api_get_responses, check_api_post_responses | from swh.web.tests.utils import check_api_get_responses, check_api_post_responses | ||||
def test_swhid_resolve_success( | def test_swhid_resolve_success( | ||||
api_client, content, directory, origin, release, revision, snapshot | api_client, content, directory, origin, release, revision, snapshot | ||||
): | ): | ||||
for obj_type, obj_id in ( | for obj_type, obj_id in ( | ||||
Show All 40 Lines | |||||
def test_swhid_resolve_invalid(api_client): | def test_swhid_resolve_invalid(api_client): | ||||
rev_id_invalid = "96db9023b8_foo_50d6c108e9a3" | rev_id_invalid = "96db9023b8_foo_50d6c108e9a3" | ||||
swhid = "swh:1:rev:%s" % rev_id_invalid | swhid = "swh:1:rev:%s" % rev_id_invalid | ||||
url = reverse("api-1-resolve-swhid", url_args={"swhid": swhid}) | url = reverse("api-1-resolve-swhid", url_args={"swhid": swhid}) | ||||
check_api_get_responses(api_client, url, status_code=400) | check_api_get_responses(api_client, url, status_code=400) | ||||
@given( | |||||
unknown_content(), | |||||
unknown_directory(), | |||||
unknown_release(), | |||||
unknown_revision(), | |||||
unknown_snapshot(), | |||||
) | |||||
def test_swhid_resolve_not_found( | def test_swhid_resolve_not_found( | ||||
api_client, | api_client, | ||||
unknown_content, | unknown_content, | ||||
unknown_directory, | unknown_directory, | ||||
unknown_release, | unknown_release, | ||||
unknown_revision, | unknown_revision, | ||||
unknown_snapshot, | unknown_snapshot, | ||||
): | ): | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |