Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/test_utils.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-2020 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 hypothesis import given | from hypothesis import given | ||||
from swh.model.hashutil import DEFAULT_ALGORITHMS | from swh.model.hashutil import DEFAULT_ALGORITHMS | ||||
from swh.web.api import utils | from swh.web.api import utils | ||||
from swh.web.common.origin_visits import get_origin_visits | from swh.web.common.origin_visits import get_origin_visits | ||||
from swh.web.common.utils import resolve_branch_alias, reverse | from swh.web.common.utils import resolve_branch_alias, reverse | ||||
from swh.web.tests.strategies import ( | from swh.web.tests.strategies import directory, origin, release, revision, snapshot | ||||
content, | |||||
directory, | |||||
origin, | |||||
release, | |||||
revision, | |||||
snapshot, | |||||
) | |||||
url_map = [ | url_map = [ | ||||
{ | { | ||||
"rule": "/other/<slug>", | "rule": "/other/<slug>", | ||||
"methods": set(["GET", "POST", "HEAD"]), | "methods": set(["GET", "POST", "HEAD"]), | ||||
"endpoint": "foo", | "endpoint": "foo", | ||||
}, | }, | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | def test_enrich_directory_entry_with_type(api_request_factory, archive_data, directory): | ||||
assert actual_directory == dir_entry | assert actual_directory == dir_entry | ||||
def test_enrich_content_without_hashes(): | def test_enrich_content_without_hashes(): | ||||
assert utils.enrich_content({"id": "123"}) == {"id": "123"} | assert utils.enrich_content({"id": "123"}) == {"id": "123"} | ||||
@given(content()) | |||||
def test_enrich_content_with_hashes(api_request_factory, content): | def test_enrich_content_with_hashes(api_request_factory, content): | ||||
for algo in DEFAULT_ALGORITHMS: | for algo in DEFAULT_ALGORITHMS: | ||||
content_data = dict(content) | content_data = dict(content) | ||||
query_string = "%s:%s" % (algo, content_data[algo]) | query_string = "%s:%s" % (algo, content_data[algo]) | ||||
Show All 18 Lines | for algo in DEFAULT_ALGORITHMS: | ||||
content_data["license_url"] = reverse( | content_data["license_url"] = reverse( | ||||
"api-1-content-license", url_args={"q": query_string}, request=request | "api-1-content-license", url_args={"q": query_string}, request=request | ||||
) | ) | ||||
assert enriched_content == content_data | assert enriched_content == content_data | ||||
@given(content()) | |||||
def test_enrich_content_with_hashes_and_top_level_url(api_request_factory, content): | def test_enrich_content_with_hashes_and_top_level_url(api_request_factory, content): | ||||
for algo in DEFAULT_ALGORITHMS: | for algo in DEFAULT_ALGORITHMS: | ||||
content_data = dict(content) | content_data = dict(content) | ||||
query_string = "%s:%s" % (algo, content_data[algo]) | query_string = "%s:%s" % (algo, content_data[algo]) | ||||
▲ Show 20 Lines • Show All 352 Lines • Show Last 20 Lines |