Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/test_utils.py
# Copyright (C) 2015-2021 The Software Heritage developers | # Copyright (C) 2015-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 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 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 468 Lines • ▼ Show 20 Lines | revision_data["children_urls"] = [ | ||||
reverse( | reverse( | ||||
"api-1-revision", url_args={"sha1_git": child_revision}, request=request | "api-1-revision", url_args={"sha1_git": child_revision}, request=request | ||||
) | ) | ||||
] | ] | ||||
assert actual_revision == revision_data | assert actual_revision == revision_data | ||||
@given(snapshot()) | |||||
def test_enrich_snapshot(api_request_factory, archive_data, snapshot): | def test_enrich_snapshot(api_request_factory, archive_data, snapshot): | ||||
snapshot_data = archive_data.snapshot_get(snapshot) | snapshot_data = archive_data.snapshot_get(snapshot) | ||||
url = reverse("api-1-snapshot", url_args={"snapshot_id": snapshot}) | url = reverse("api-1-snapshot", url_args={"snapshot_id": snapshot}) | ||||
request = api_request_factory.get(url) | request = api_request_factory.get(url) | ||||
actual_snapshot = utils.enrich_snapshot(snapshot_data, request) | actual_snapshot = utils.enrich_snapshot(snapshot_data, request) | ||||
▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines |