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-2019 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.api.views import check_api_get_responses | |||||
from swh.web.tests.data import random_sha1 | from swh.web.tests.data import random_sha1 | ||||
from swh.web.tests.strategies import new_snapshot, snapshot | from swh.web.tests.strategies import new_snapshot, snapshot | ||||
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) | ||||
expected_data = {**archive_data.snapshot_get(snapshot), "next_branch": None} | expected_data = {**archive_data.snapshot_get(snapshot), "next_branch": None} | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
@given(snapshot()) | @given(snapshot()) | ||||
def test_api_snapshot_uppercase(api_client, snapshot): | def test_api_snapshot_uppercase(api_client, snapshot): | ||||
url = reverse( | url = reverse( | ||||
"api-1-snapshot-uppercase-checksum", url_args={"snapshot_id": snapshot.upper()} | "api-1-snapshot-uppercase-checksum", url_args={"snapshot_id": snapshot.upper()} | ||||
) | ) | ||||
resp = api_client.get(url) | resp = check_http_get_response(api_client, url, status_code=302) | ||||
assert resp.status_code == 302 | |||||
redirect_url = reverse( | redirect_url = reverse( | ||||
"api-1-snapshot-uppercase-checksum", url_args={"snapshot_id": snapshot} | "api-1-snapshot-uppercase-checksum", url_args={"snapshot_id": snapshot} | ||||
) | ) | ||||
assert resp["location"] == redirect_url | assert resp["location"] == redirect_url | ||||
Show All 10 Lines |