Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/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 | ||||
import random | import random | ||||
from urllib.parse import quote | from urllib.parse import quote | ||||
from hypothesis import given | from hypothesis import given | ||||
from swh.model.model import Origin | from swh.model.model import Origin | ||||
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.django_asserts import assert_contains | from swh.web.tests.django_asserts import assert_contains | ||||
from swh.web.tests.strategies import ( | from swh.web.tests.strategies import directory, origin, release, revision, snapshot | ||||
content, | |||||
directory, | |||||
origin, | |||||
release, | |||||
revision, | |||||
snapshot, | |||||
) | |||||
from swh.web.tests.utils import check_html_get_response | from swh.web.tests.utils import check_html_get_response | ||||
@given(content()) | |||||
def test_content_id_browse(client, content): | def test_content_id_browse(client, content): | ||||
cnt_sha1_git = content["sha1_git"] | cnt_sha1_git = content["sha1_git"] | ||||
swhid = gen_swhid(ObjectType.CONTENT, cnt_sha1_git) | swhid = gen_swhid(ObjectType.CONTENT, cnt_sha1_git) | ||||
for swhid_ in (swhid, swhid.upper()): | for swhid_ in (swhid, swhid.upper()): | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid_}) | url = reverse("browse-swhid", url_args={"swhid": swhid_}) | ||||
query_string = "sha1_git:" + cnt_sha1_git | query_string = "sha1_git:" + cnt_sha1_git | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | |||||
@given(release()) | @given(release()) | ||||
def test_bad_id_browse(client, release): | def test_bad_id_browse(client, release): | ||||
swhid = f"swh:1:foo:{release}" | swhid = f"swh:1:foo:{release}" | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid}) | url = reverse("browse-swhid", url_args={"swhid": swhid}) | ||||
check_html_get_response(client, url, status_code=400) | check_html_get_response(client, url, status_code=400) | ||||
@given(content()) | |||||
def test_content_id_optional_parts_browse(client, archive_data, content): | def test_content_id_optional_parts_browse(client, archive_data, content): | ||||
cnt_sha1_git = content["sha1_git"] | cnt_sha1_git = content["sha1_git"] | ||||
origin_url = "https://github.com/user/repo" | origin_url = "https://github.com/user/repo" | ||||
archive_data.origin_add([Origin(url=origin_url)]) | archive_data.origin_add([Origin(url=origin_url)]) | ||||
swhid = gen_swhid( | swhid = gen_swhid( | ||||
ObjectType.CONTENT, | ObjectType.CONTENT, | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |