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 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 ( | from swh.web.tests.strategies import ( | ||||
directory, | |||||
origin, | origin, | ||||
release, | release, | ||||
revision, | revision, | ||||
snapshot, | snapshot, | ||||
unknown_content, | unknown_content, | ||||
unknown_directory, | unknown_directory, | ||||
unknown_release, | unknown_release, | ||||
unknown_revision, | unknown_revision, | ||||
unknown_snapshot, | 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 | ||||
@given(origin(), directory(), release(), revision(), snapshot()) | @given(origin(), release(), revision(), snapshot()) | ||||
def test_swhid_resolve_success( | def test_swhid_resolve_success( | ||||
api_client, client, content, origin, directory, release, revision, snapshot | api_client, client, content, directory, origin, release, revision, snapshot | ||||
): | ): | ||||
for obj_type, obj_id in ( | for obj_type, obj_id in ( | ||||
(ObjectType.CONTENT, content["sha1_git"]), | (ObjectType.CONTENT, content["sha1_git"]), | ||||
(ObjectType.DIRECTORY, directory), | (ObjectType.DIRECTORY, directory), | ||||
(ObjectType.RELEASE, release), | (ObjectType.RELEASE, release), | ||||
(ObjectType.REVISION, revision), | (ObjectType.REVISION, revision), | ||||
(ObjectType.SNAPSHOT, snapshot), | (ObjectType.SNAPSHOT, snapshot), | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | |||||
def test_swh_origin_id_not_resolvable(api_client): | def test_swh_origin_id_not_resolvable(api_client): | ||||
ori_swhid = "swh:1:ori:8068d0075010b590762c6cb5682ed53cb3c13deb" | ori_swhid = "swh:1:ori:8068d0075010b590762c6cb5682ed53cb3c13deb" | ||||
url = reverse("api-1-resolve-swhid", url_args={"swhid": ori_swhid}) | url = reverse("api-1-resolve-swhid", url_args={"swhid": ori_swhid}) | ||||
check_api_get_responses(api_client, url, status_code=400) | check_api_get_responses(api_client, url, status_code=400) | ||||
@given(directory(), release(), revision(), snapshot()) | @given(release(), revision(), snapshot()) | ||||
def test_api_known_swhid_all_present( | def test_api_known_swhid_all_present( | ||||
api_client, content, directory, release, revision, snapshot | api_client, content, directory, release, revision, snapshot | ||||
): | ): | ||||
input_swhids = [ | input_swhids = [ | ||||
gen_swhid(ObjectType.CONTENT, content["sha1_git"]), | gen_swhid(ObjectType.CONTENT, content["sha1_git"]), | ||||
gen_swhid(ObjectType.DIRECTORY, directory), | gen_swhid(ObjectType.DIRECTORY, directory), | ||||
gen_swhid(ObjectType.REVISION, revision), | gen_swhid(ObjectType.REVISION, revision), | ||||
gen_swhid(ObjectType.RELEASE, release), | gen_swhid(ObjectType.RELEASE, release), | ||||
gen_swhid(ObjectType.SNAPSHOT, snapshot), | gen_swhid(ObjectType.SNAPSHOT, snapshot), | ||||
] | ] | ||||
url = reverse("api-1-known") | url = reverse("api-1-known") | ||||
resp = check_api_post_responses(api_client, url, data=input_swhids, status_code=200) | resp = check_api_post_responses(api_client, url, data=input_swhids, status_code=200) | ||||
assert resp.data == {swhid: {"known": True} for swhid in input_swhids} | assert resp.data == {swhid: {"known": True} for swhid in input_swhids} | ||||
@given(directory()) | |||||
def test_api_known_swhid_some_present(api_client, content, directory): | def test_api_known_swhid_some_present(api_client, content, directory): | ||||
content_ = gen_swhid(ObjectType.CONTENT, content["sha1_git"]) | content_ = gen_swhid(ObjectType.CONTENT, content["sha1_git"]) | ||||
directory_ = gen_swhid(ObjectType.DIRECTORY, directory) | directory_ = gen_swhid(ObjectType.DIRECTORY, directory) | ||||
unknown_revision_ = gen_swhid(ObjectType.REVISION, random_sha1()) | unknown_revision_ = gen_swhid(ObjectType.REVISION, random_sha1()) | ||||
unknown_release_ = gen_swhid(ObjectType.RELEASE, random_sha1()) | unknown_release_ = gen_swhid(ObjectType.RELEASE, random_sha1()) | ||||
unknown_snapshot_ = gen_swhid(ObjectType.SNAPSHOT, random_sha1()) | unknown_snapshot_ = gen_swhid(ObjectType.SNAPSHOT, random_sha1()) | ||||
input_swhids = [ | input_swhids = [ | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |