Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/misc/test_badges.py
# Copyright (C) 2019-2021 The Software Heritage developers | # Copyright (C) 2019-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 corsheaders.middleware import ACCESS_CONTROL_ALLOW_ORIGIN | from corsheaders.middleware import ACCESS_CONTROL_ALLOW_ORIGIN | ||||
from hypothesis import given | from hypothesis import given | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.swhids import ObjectType, QualifiedSWHID | from swh.model.swhids import ObjectType, QualifiedSWHID | ||||
from swh.web.common import archive | from swh.web.common import archive | ||||
from swh.web.common.identifiers import resolve_swhid | from swh.web.common.identifiers import resolve_swhid | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import reverse | ||||
from swh.web.misc.badges import _badge_config, _get_logo_data | from swh.web.misc.badges import _badge_config, _get_logo_data | ||||
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 new_origin | ||||
invalid_sha1, | |||||
new_origin, | |||||
unknown_content, | |||||
unknown_directory, | |||||
unknown_release, | |||||
unknown_revision, | |||||
unknown_snapshot, | |||||
) | |||||
from swh.web.tests.utils import check_http_get_response | from swh.web.tests.utils import check_http_get_response | ||||
def test_content_badge(client, content): | def test_content_badge(client, content): | ||||
_test_badge_endpoints(client, "content", content["sha1_git"]) | _test_badge_endpoints(client, "content", content["sha1_git"]) | ||||
def test_directory_badge(client, directory): | def test_directory_badge(client, directory): | ||||
Show All 11 Lines | |||||
def test_revision_badge(client, revision): | def test_revision_badge(client, revision): | ||||
_test_badge_endpoints(client, "revision", revision) | _test_badge_endpoints(client, "revision", revision) | ||||
def test_snapshot_badge(client, snapshot): | def test_snapshot_badge(client, snapshot): | ||||
_test_badge_endpoints(client, "snapshot", snapshot) | _test_badge_endpoints(client, "snapshot", snapshot) | ||||
@given( | @given(new_origin(),) | ||||
unknown_content(), | |||||
unknown_directory(), | |||||
new_origin(), | |||||
unknown_release(), | |||||
unknown_revision(), | |||||
unknown_snapshot(), | |||||
invalid_sha1(), | |||||
) | |||||
def test_badge_errors( | def test_badge_errors( | ||||
client, | client, | ||||
unknown_content, | unknown_content, | ||||
unknown_directory, | unknown_directory, | ||||
new_origin, | |||||
unknown_release, | unknown_release, | ||||
unknown_revision, | unknown_revision, | ||||
unknown_snapshot, | unknown_snapshot, | ||||
invalid_sha1, | invalid_sha1, | ||||
new_origin, | |||||
): | ): | ||||
for object_type, object_id in ( | for object_type, object_id in ( | ||||
("content", unknown_content["sha1_git"]), | ("content", unknown_content["sha1_git"]), | ||||
("directory", unknown_directory), | ("directory", unknown_directory), | ||||
("origin", new_origin), | ("origin", new_origin), | ||||
("release", unknown_release), | ("release", unknown_release), | ||||
("revision", unknown_revision), | ("revision", unknown_revision), | ||||
("snapshot", unknown_snapshot), | ("snapshot", unknown_snapshot), | ||||
▲ Show 20 Lines • Show All 118 Lines • Show Last 20 Lines |