Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_snapshot.py
# Copyright (C) 2018-2019 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 hypothesis import given | from hypothesis import given | ||||
from swh.model.hashutil import hash_to_hex | from swh.model.hashutil import hash_to_hex | ||||
from swh.model.model import Snapshot | from swh.model.model import Snapshot | ||||
from swh.web.api.utils import enrich_snapshot | from swh.web.api.utils import enrich_snapshot | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import reverse | ||||
from swh.web.tests.data import random_sha1 | from swh.web.tests.data import random_sha1 | ||||
from swh.web.tests.strategies import ( | from swh.web.tests.strategies import new_snapshot, snapshot | ||||
new_snapshot, | |||||
origin_with_pull_request_branches, | |||||
snapshot, | |||||
) | |||||
from swh.web.tests.utils import check_api_get_responses, check_http_get_response | from swh.web.tests.utils import check_api_get_responses, check_http_get_response | ||||
@given(snapshot()) | @given(snapshot()) | ||||
def test_api_snapshot(api_client, archive_data, snapshot): | def test_api_snapshot(api_client, archive_data, snapshot): | ||||
url = reverse("api-1-snapshot", url_args={"snapshot_id": snapshot}) | url = reverse("api-1-snapshot", url_args={"snapshot_id": snapshot}) | ||||
rv = check_api_get_responses(api_client, url, status_code=200) | rv = check_api_get_responses(api_client, url, status_code=200) | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | def test_api_snapshot_null_branch(api_client, archive_data, new_snapshot): | ||||
for branch in snp_dict["branches"].keys(): | for branch in snp_dict["branches"].keys(): | ||||
snp_dict["branches"][branch] = None | snp_dict["branches"][branch] = None | ||||
break | break | ||||
archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) | archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) | ||||
url = reverse("api-1-snapshot", url_args={"snapshot_id": snp_id}) | url = reverse("api-1-snapshot", url_args={"snapshot_id": snp_id}) | ||||
check_api_get_responses(api_client, url, status_code=200) | check_api_get_responses(api_client, url, status_code=200) | ||||
@given(origin_with_pull_request_branches()) | |||||
def test_api_snapshot_no_pull_request_branches_filtering( | def test_api_snapshot_no_pull_request_branches_filtering( | ||||
api_client, archive_data, origin | api_client, archive_data, origin_with_pull_request_branches | ||||
): | ): | ||||
"""Pull request branches should not be filtered out when querying | """Pull request branches should not be filtered out when querying | ||||
a snapshot with the Web API.""" | a snapshot with the Web API.""" | ||||
snapshot = archive_data.snapshot_get_latest(origin.url) | snapshot = archive_data.snapshot_get_latest(origin_with_pull_request_branches.url) | ||||
url = reverse("api-1-snapshot", url_args={"snapshot_id": snapshot["id"]}) | url = reverse("api-1-snapshot", url_args={"snapshot_id": snapshot["id"]}) | ||||
resp = check_api_get_responses(api_client, url, status_code=200) | resp = check_api_get_responses(api_client, url, status_code=200) | ||||
assert any([b.startswith("refs/pull/") for b in resp.data["branches"]]) | assert any([b.startswith("refs/pull/") for b in resp.data["branches"]]) |