Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_identifiers.py
Show All 22 Lines | |||||
) | ) | ||||
from swh.web.tests.utils import check_html_get_response | from swh.web.tests.utils import check_html_get_response | ||||
@given(content()) | @given(content()) | ||||
def test_content_id_browse(client, content): | def test_content_id_browse(client, content): | ||||
cnt_sha1_git = content["sha1_git"] | cnt_sha1_git = content["sha1_git"] | ||||
swhid = gen_swhid(CONTENT, cnt_sha1_git) | swhid = gen_swhid(CONTENT, cnt_sha1_git) | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid}) | |||||
for swhid_ in (swhid, swhid.upper()): | |||||
url = reverse("browse-swhid", url_args={"swhid": swhid_}) | |||||
query_string = "sha1_git:" + cnt_sha1_git | query_string = "sha1_git:" + cnt_sha1_git | ||||
content_browse_url = reverse( | content_browse_url = reverse( | ||||
"browse-content", url_args={"query_string": query_string} | "browse-content", url_args={"query_string": query_string} | ||||
) | ) | ||||
resp = check_html_get_response(client, url, status_code=302) | resp = check_html_get_response(client, url, status_code=302) | ||||
ardumont: What about making the `gen_swhid`generate indifferently upper and lower (at least one of each)… | |||||
Done Inline Actionsgen_swhid uses the QualifiedSWHID class under the hood so this will not work and we do not want to promote SWHID v1 with uppercase chars in it. anlambert: `gen_swhid` uses the `QualifiedSWHID` class under the hood so this will not work and we do not… | |||||
Not Done Inline Actionsack ardumont: ack | |||||
assert resp["location"] == content_browse_url | assert resp["location"] == content_browse_url | ||||
@given(directory()) | @given(directory()) | ||||
def test_directory_id_browse(client, directory): | def test_directory_id_browse(client, directory): | ||||
swhid = gen_swhid(DIRECTORY, directory) | swhid = gen_swhid(DIRECTORY, directory) | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid}) | |||||
directory_browse_url = reverse("browse-directory", url_args={"sha1_git": directory}) | for swhid_ in (swhid, swhid.upper()): | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid_}) | |||||
directory_browse_url = reverse( | |||||
"browse-directory", url_args={"sha1_git": directory} | |||||
) | |||||
resp = check_html_get_response(client, url, status_code=302) | resp = check_html_get_response(client, url, status_code=302) | ||||
assert resp["location"] == directory_browse_url | assert resp["location"] == directory_browse_url | ||||
@given(revision()) | @given(revision()) | ||||
def test_revision_id_browse(client, revision): | def test_revision_id_browse(client, revision): | ||||
swhid = gen_swhid(REVISION, revision) | swhid = gen_swhid(REVISION, revision) | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid}) | |||||
revision_browse_url = reverse("browse-revision", url_args={"sha1_git": revision}) | for swhid_ in (swhid, swhid.upper()): | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid_}) | |||||
revision_browse_url = reverse( | |||||
"browse-revision", url_args={"sha1_git": revision} | |||||
) | |||||
resp = check_html_get_response(client, url, status_code=302) | resp = check_html_get_response(client, url, status_code=302) | ||||
assert resp["location"] == revision_browse_url | assert resp["location"] == revision_browse_url | ||||
query_params = {"origin_url": "https://github.com/user/repo"} | query_params = {"origin_url": "https://github.com/user/repo"} | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid}, query_params=query_params) | url = reverse( | ||||
"browse-swhid", url_args={"swhid": swhid_}, query_params=query_params | |||||
) | |||||
revision_browse_url = reverse( | revision_browse_url = reverse( | ||||
"browse-revision", url_args={"sha1_git": revision}, query_params=query_params | "browse-revision", | ||||
url_args={"sha1_git": revision}, | |||||
query_params=query_params, | |||||
) | ) | ||||
resp = check_html_get_response(client, url, status_code=302) | resp = check_html_get_response(client, url, status_code=302) | ||||
assert resp["location"] == revision_browse_url | assert resp["location"] == revision_browse_url | ||||
@given(release()) | @given(release()) | ||||
def test_release_id_browse(client, release): | def test_release_id_browse(client, release): | ||||
swhid = gen_swhid(RELEASE, release) | swhid = gen_swhid(RELEASE, release) | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid}) | |||||
for swhid_ in (swhid, swhid.upper()): | |||||
url = reverse("browse-swhid", url_args={"swhid": swhid_}) | |||||
release_browse_url = reverse("browse-release", url_args={"sha1_git": release}) | release_browse_url = reverse("browse-release", url_args={"sha1_git": release}) | ||||
resp = check_html_get_response(client, url, status_code=302) | resp = check_html_get_response(client, url, status_code=302) | ||||
assert resp["location"] == release_browse_url | assert resp["location"] == release_browse_url | ||||
query_params = {"origin_url": "https://github.com/user/repo"} | query_params = {"origin_url": "https://github.com/user/repo"} | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid}, query_params=query_params) | url = reverse( | ||||
"browse-swhid", url_args={"swhid": swhid_}, query_params=query_params | |||||
) | |||||
release_browse_url = reverse( | release_browse_url = reverse( | ||||
"browse-release", url_args={"sha1_git": release}, query_params=query_params | "browse-release", url_args={"sha1_git": release}, query_params=query_params | ||||
) | ) | ||||
resp = check_html_get_response(client, url, status_code=302) | resp = check_html_get_response(client, url, status_code=302) | ||||
assert resp["location"] == release_browse_url | assert resp["location"] == release_browse_url | ||||
@given(snapshot()) | @given(snapshot()) | ||||
def test_snapshot_id_browse(client, snapshot): | def test_snapshot_id_browse(client, snapshot): | ||||
swhid = gen_swhid(SNAPSHOT, snapshot) | swhid = gen_swhid(SNAPSHOT, snapshot) | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid}) | |||||
snapshot_browse_url = reverse("browse-snapshot", url_args={"snapshot_id": snapshot}) | for swhid_ in (swhid, swhid.upper()): | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid_}) | |||||
snapshot_browse_url = reverse( | |||||
"browse-snapshot", url_args={"snapshot_id": snapshot} | |||||
) | |||||
resp = check_html_get_response(client, url, status_code=302) | resp = check_html_get_response(client, url, status_code=302) | ||||
assert resp["location"] == snapshot_browse_url | assert resp["location"] == snapshot_browse_url | ||||
query_params = {"origin_url": "https://github.com/user/repo"} | query_params = {"origin_url": "https://github.com/user/repo"} | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid}, query_params=query_params) | url = reverse( | ||||
"browse-swhid", url_args={"swhid": swhid_}, query_params=query_params | |||||
) | |||||
release_browse_url = reverse( | release_browse_url = reverse( | ||||
"browse-snapshot", url_args={"snapshot_id": snapshot}, query_params=query_params | "browse-snapshot", | ||||
url_args={"snapshot_id": snapshot}, | |||||
query_params=query_params, | |||||
) | ) | ||||
resp = check_html_get_response(client, url, status_code=302) | resp = check_html_get_response(client, url, status_code=302) | ||||
assert resp["location"] == release_browse_url | assert resp["location"] == release_browse_url | ||||
@given(release()) | @given(release()) | ||||
def test_bad_id_browse(client, release): | def test_bad_id_browse(client, release): | ||||
swhid = f"swh:1:foo:{release}" | swhid = f"swh:1:foo:{release}" | ||||
url = reverse("browse-swhid", url_args={"swhid": swhid}) | url = reverse("browse-swhid", url_args={"swhid": swhid}) | ||||
check_html_get_response(client, url, status_code=400) | check_html_get_response(client, url, status_code=400) | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |
What about making the gen_swhidgenerate indifferently upper and lower (at least one of each) case swhid?