Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_origin.py
Show First 20 Lines • Show All 855 Lines • ▼ Show 20 Lines | for browse_context in ( | ||||
"directory", | "directory", | ||||
"log", | "log", | ||||
"branches", | "branches", | ||||
"releases", | "releases", | ||||
"visits", | "visits", | ||||
): | ): | ||||
url = reverse(f"browse-origin-{browse_context}") | url = reverse(f"browse-origin-{browse_context}") | ||||
if browse_context in ["log", "branches"]: | |||||
# FIXME; temporory fix for partial T3608 | |||||
# Will be removed once every origin duplicate URL is moved | |||||
resp = check_html_get_response(client, url, status_code=302) | |||||
assert f"/snapshot-{browse_context}/" in resp.url | |||||
else: | |||||
resp = check_html_get_response( | resp = check_html_get_response( | ||||
client, url, status_code=400, template_used="error.html" | client, url, status_code=400, template_used="error.html" | ||||
) | ) | ||||
assert_contains( | assert_contains( | ||||
resp, "An origin URL must be provided as query parameter.", status_code=400 | resp, | ||||
"An origin URL must be provided as query parameter.", | |||||
status_code=400, | |||||
) | ) | ||||
anlambert: Please move the redirection check in a separate test. | |||||
def _origin_content_view_test_helper( | def _origin_content_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin_info, | origin_info, | ||||
origin_visit, | origin_visit, | ||||
Done Inline ActionsThis test is not complete and can be improved, use this instead: @given(origin()) @pytest.mark.parametrize("browse_context", ["log"]) def test_origin_view_redirects(client, browse_context, origin): query_params = {"origin_url": origin["url"]} url = reverse(f"browse-origin-{browse_context}", query_params=query_params) resp = check_html_get_response(client, url, status_code=301) assert resp["location"] == reverse( f"browse-snapshot-{browse_context}", query_params=query_params ) anlambert: This test is not complete and can be improved, use this instead:
```lang=python
@given(origin… | |||||
Done Inline ActionsThis should be assert "/snapshot/{browse_context}/" in resp.url jayeshv: This should be assert "/snapshot/{browse_context}/" in resp.url
I will fix this with… | |||||
snapshot_sizes, | snapshot_sizes, | ||||
origin_branches, | origin_branches, | ||||
origin_releases, | origin_releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
content, | content, | ||||
visit_id=None, | visit_id=None, | ||||
timestamp=None, | timestamp=None, | ||||
snapshot_id=None, | snapshot_id=None, | ||||
▲ Show 20 Lines • Show All 270 Lines • ▼ Show 20 Lines | |||||
def _origin_branches_test_helper( | def _origin_branches_test_helper( | ||||
client, origin_info, origin_snapshot, snapshot_sizes, snapshot_id=None | client, origin_info, origin_snapshot, snapshot_sizes, snapshot_id=None | ||||
): | ): | ||||
query_params = {"origin_url": origin_info["url"], "snapshot": snapshot_id} | query_params = {"origin_url": origin_info["url"], "snapshot": snapshot_id} | ||||
url = reverse("browse-origin-branches", query_params=query_params) | url = reverse("browse-origin-branches", query_params=query_params) | ||||
resp = check_html_get_response(client, url, status_code=302) | |||||
redirected_url = resp.url | |||||
assert "snapshot-branches" in redirected_url | |||||
resp = check_html_get_response( | resp = check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/branches.html" | client, redirected_url, status_code=200, template_used="browse/branches.html" | ||||
) | ) | ||||
origin_branches = origin_snapshot[0] | origin_branches = origin_snapshot[0] | ||||
origin_releases = origin_snapshot[1] | origin_releases = origin_snapshot[1] | ||||
origin_branches_url = reverse("browse-origin-branches", query_params=query_params) | origin_branches_url = reverse("browse-snapshot-branches", query_params=query_params) | ||||
assert_contains(resp, f'href="{escape(origin_branches_url)}"') | assert_contains(resp, f'"{escape(origin_branches_url)}"') | ||||
assert_contains(resp, f"Branches ({snapshot_sizes['revision']})") | assert_contains(resp, f"Branches ({snapshot_sizes['revision']})") | ||||
origin_releases_url = reverse("browse-origin-releases", query_params=query_params) | origin_releases_url = reverse("browse-origin-releases", query_params=query_params) | ||||
nb_releases = len(origin_releases) | nb_releases = len(origin_releases) | ||||
if nb_releases > 0: | if nb_releases > 0: | ||||
assert_contains(resp, f'href="{escape(origin_releases_url)}">') | assert_contains(resp, f'href="{escape(origin_releases_url)}">') | ||||
assert_contains(resp, f"Releases ({snapshot_sizes['release']})") | assert_contains(resp, f"Releases ({snapshot_sizes['release']})") | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | visit_status = OriginVisitStatus( | ||||
origin=new_origin.url, | origin=new_origin.url, | ||||
visit=visit.visit, | visit=visit.visit, | ||||
date=now(), | date=now(), | ||||
status="full", | status="full", | ||||
snapshot=snp_dict["id"], | snapshot=snp_dict["id"], | ||||
) | ) | ||||
archive_data.origin_visit_status_add([visit_status]) | archive_data.origin_visit_status_add([visit_status]) | ||||
url = reverse("browse-origin-branches", query_params={"origin_url": new_origin.url}) | url = reverse( | ||||
"browse-snapshot-branches", query_params={"origin_url": new_origin.url} | |||||
) | |||||
resp = check_html_get_response( | resp = check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/branches.html" | client, url, status_code=200, template_used="browse/branches.html" | ||||
) | ) | ||||
assert_contains(resp, '<ul class="pagination') | assert_contains(resp, '<ul class="pagination') | ||||
def _check_origin_link(resp, origin_url): | def _check_origin_link(resp, origin_url): | ||||
browse_origin_url = reverse( | browse_origin_url = reverse( | ||||
"browse-origin", query_params={"origin_url": origin_url} | "browse-origin", query_params={"origin_url": origin_url} | ||||
) | ) | ||||
assert_contains(resp, f'href="{browse_origin_url}"') | assert_contains(resp, f'href="{browse_origin_url}"') | ||||
@given(origin_with_pull_request_branches()) | @given(origin_with_pull_request_branches()) | ||||
def test_pull_request_branches_filtering(client, origin): | def test_pull_request_branches_filtering(client, origin): | ||||
# check no pull request branches are displayed in the Branches / Releases dropdown | # check no pull request branches are displayed in the Branches / Releases dropdown | ||||
url = reverse("browse-origin-directory", query_params={"origin_url": origin.url}) | url = reverse("browse-origin-directory", query_params={"origin_url": origin.url}) | ||||
resp = check_html_get_response( | resp = check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/directory.html" | client, url, status_code=200, template_used="browse/directory.html" | ||||
) | ) | ||||
assert_not_contains(resp, "refs/pull/") | assert_not_contains(resp, "refs/pull/") | ||||
# check no pull request branches are displayed in the branches view | # check no pull request branches are displayed in the branches view | ||||
url = reverse("browse-origin-branches", query_params={"origin_url": origin.url}) | url = reverse("browse-snapshot-branches", query_params={"origin_url": origin.url}) | ||||
resp = check_html_get_response( | resp = check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/branches.html" | client, url, status_code=200, template_used="browse/branches.html" | ||||
) | ) | ||||
assert_not_contains(resp, "refs/pull/") | assert_not_contains(resp, "refs/pull/") | ||||
@given(origin_with_pull_request_branches()) | @given(origin_with_pull_request_branches()) | ||||
def test_browse_pull_request_branch(client, archive_data, origin): | def test_browse_pull_request_branch(client, archive_data, origin): | ||||
Show All 15 Lines |
Please move the redirection check in a separate test.