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 directory, origin, release, revision, snapshot | from swh.web.tests.strategies import 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 152 Lines • ▼ Show 20 Lines | def test_enrich_release_release_target(api_request_factory, archive_data, release): | ||||
assert actual_release == release_data | assert actual_release == release_data | ||||
def test_enrich_directory_entry_no_type(): | def test_enrich_directory_entry_no_type(): | ||||
assert utils.enrich_directory_entry({"id": "dir-id"}) == {"id": "dir-id"} | assert utils.enrich_directory_entry({"id": "dir-id"}) == {"id": "dir-id"} | ||||
@given(directory()) | |||||
def test_enrich_directory_entry_with_type(api_request_factory, archive_data, directory): | def test_enrich_directory_entry_with_type(api_request_factory, archive_data, directory): | ||||
dir_content = archive_data.directory_ls(directory) | dir_content = archive_data.directory_ls(directory) | ||||
dir_entry = random.choice(dir_content) | dir_entry = random.choice(dir_content) | ||||
url = reverse("api-1-directory", url_args={"sha1_git": directory}) | url = reverse("api-1-directory", url_args={"sha1_git": directory}) | ||||
request = api_request_factory.get(url) | request = api_request_factory.get(url) | ||||
▲ Show 20 Lines • Show All 425 Lines • Show Last 20 Lines |