Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_origin.py
Show All 25 Lines | |||||
from swh.web.common.identifiers import gen_swhid | from swh.web.common.identifiers import gen_swhid | ||||
from swh.web.common.utils import ( | from swh.web.common.utils import ( | ||||
format_utc_iso_date, | format_utc_iso_date, | ||||
gen_path_info, | gen_path_info, | ||||
parse_iso8601_date_to_utc, | parse_iso8601_date_to_utc, | ||||
reverse, | reverse, | ||||
) | ) | ||||
from swh.web.tests.data import get_content, random_sha1 | from swh.web.tests.data import get_content, random_sha1 | ||||
from swh.web.tests.django_asserts import assert_contains, assert_template_used | from swh.web.tests.django_asserts import assert_contains | ||||
from swh.web.tests.strategies import ( | from swh.web.tests.strategies import ( | ||||
new_origin, | new_origin, | ||||
new_snapshot, | new_snapshot, | ||||
origin, | origin, | ||||
origin_with_multiple_visits, | origin_with_multiple_visits, | ||||
origin_with_releases, | origin_with_releases, | ||||
) | ) | ||||
from swh.web.tests.strategies import release as existing_release | from swh.web.tests.strategies import release as existing_release | ||||
from swh.web.tests.strategies import revisions, unknown_revision, visit_dates | from swh.web.tests.strategies import revisions, unknown_revision, visit_dates | ||||
from swh.web.tests.utils import check_html_get_response | |||||
@given(origin_with_multiple_visits()) | @given(origin_with_multiple_visits()) | ||||
def test_origin_visits_browse(client, archive_data, origin): | def test_origin_visits_browse(client, archive_data, origin): | ||||
url = reverse("browse-origin-visits", query_params={"origin_url": origin["url"]}) | url = reverse("browse-origin-visits", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 200 | resp = check_html_get_response( | ||||
assert_template_used(resp, "browse/origin-visits.html") | client, url, status_code=200, template_used="browse/origin-visits.html" | ||||
) | |||||
url = reverse("browse-origin-visits", query_params={"origin_url": origin["url"]}) | |||||
resp = client.get(url) | |||||
assert resp.status_code == 200 | |||||
assert_template_used(resp, "browse/origin-visits.html") | |||||
visits = archive_data.origin_visit_get(origin["url"]) | visits = archive_data.origin_visit_get(origin["url"]) | ||||
for v in visits: | for v in visits: | ||||
vdate = format_utc_iso_date(v["date"], "%Y-%m-%dT%H:%M:%SZ") | vdate = format_utc_iso_date(v["date"], "%Y-%m-%dT%H:%M:%SZ") | ||||
browse_dir_url = reverse( | browse_dir_url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={"origin_url": origin["url"], "timestamp": vdate}, | query_params={"origin_url": origin["url"], "timestamp": vdate}, | ||||
▲ Show 20 Lines • Show All 379 Lines • ▼ Show 20 Lines | visit_status = OriginVisitStatus( | ||||
status="partial", | status="partial", | ||||
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( | url = reverse( | ||||
"browse-origin-directory", query_params={"origin_url": new_origin.url} | "browse-origin-directory", query_params={"origin_url": new_origin.url} | ||||
) | ) | ||||
rv = client.get(url) | |||||
assert rv.status_code == 200 | check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/directory.html" | |||||
) | |||||
@given( | @given( | ||||
new_origin(), | new_origin(), | ||||
new_snapshot(min_size=4, max_size=4), | new_snapshot(min_size=4, max_size=4), | ||||
visit_dates(), | visit_dates(), | ||||
revisions(min_size=4, max_size=4), | revisions(min_size=4, max_size=4), | ||||
) | ) | ||||
Show All 20 Lines | visit_status = OriginVisitStatus( | ||||
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( | url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={"origin_url": new_origin.url, "branch": "invalid_branch"}, | query_params={"origin_url": new_origin.url, "branch": "invalid_branch"}, | ||||
) | ) | ||||
rv = client.get(url) | |||||
assert rv.status_code == 404 | check_html_get_response(client, url, status_code=404, template_used="error.html") | ||||
@given(new_origin()) | @given(new_origin()) | ||||
def test_browse_visits_origin_not_found(client, new_origin): | def test_browse_visits_origin_not_found(client, new_origin): | ||||
url = reverse("browse-origin-visits", query_params={"origin_url": new_origin.url}) | url = reverse("browse-origin-visits", query_params={"origin_url": new_origin.url}) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 404 | resp = check_html_get_response( | ||||
assert_template_used(resp, "error.html") | client, url, status_code=404, template_used="error.html" | ||||
) | |||||
assert_contains( | assert_contains( | ||||
resp, f"Origin with url {new_origin.url} not found", status_code=404 | resp, f"Origin with url {new_origin.url} not found", status_code=404 | ||||
) | ) | ||||
@given(origin()) | @given(origin()) | ||||
def test_browse_origin_directory_no_visit(client, mocker, origin): | def test_browse_origin_directory_no_visit(client, mocker, origin): | ||||
mock_get_origin_visits = mocker.patch( | mock_get_origin_visits = mocker.patch( | ||||
"swh.web.common.origin_visits.get_origin_visits" | "swh.web.common.origin_visits.get_origin_visits" | ||||
) | ) | ||||
mock_get_origin_visits.return_value = [] | mock_get_origin_visits.return_value = [] | ||||
mock_archive = mocker.patch("swh.web.common.origin_visits.archive") | mock_archive = mocker.patch("swh.web.common.origin_visits.archive") | ||||
mock_archive.lookup_origin_visit_latest.return_value = None | mock_archive.lookup_origin_visit_latest.return_value = None | ||||
url = reverse("browse-origin-directory", query_params={"origin_url": origin["url"]}) | url = reverse("browse-origin-directory", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 404 | resp = check_html_get_response( | ||||
assert_template_used(resp, "error.html") | client, url, status_code=404, template_used="error.html" | ||||
) | |||||
assert_contains(resp, "No valid visit", status_code=404) | assert_contains(resp, "No valid visit", status_code=404) | ||||
assert not mock_get_origin_visits.called | assert not mock_get_origin_visits.called | ||||
@given(origin()) | @given(origin()) | ||||
def test_browse_origin_directory_unknown_visit(client, mocker, origin): | def test_browse_origin_directory_unknown_visit(client, mocker, origin): | ||||
mock_get_origin_visits = mocker.patch( | mock_get_origin_visits = mocker.patch( | ||||
"swh.web.common.origin_visits.get_origin_visits" | "swh.web.common.origin_visits.get_origin_visits" | ||||
) | ) | ||||
mock_get_origin_visits.return_value = [{"visit": 1}] | mock_get_origin_visits.return_value = [{"visit": 1}] | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={"origin_url": origin["url"], "visit_id": 2}, | query_params={"origin_url": origin["url"], "visit_id": 2}, | ||||
) | ) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 404 | resp = check_html_get_response( | ||||
assert_template_used(resp, "error.html") | client, url, status_code=404, template_used="error.html" | ||||
) | |||||
assert re.search("Visit.*not found", resp.content.decode("utf-8")) | assert re.search("Visit.*not found", resp.content.decode("utf-8")) | ||||
assert mock_get_origin_visits.called | assert mock_get_origin_visits.called | ||||
@given(origin()) | @given(origin()) | ||||
def test_browse_origin_directory_not_found(client, origin): | def test_browse_origin_directory_not_found(client, origin): | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={"origin_url": origin["url"], "path": "/invalid/dir/path/"}, | query_params={"origin_url": origin["url"], "path": "/invalid/dir/path/"}, | ||||
) | ) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 404 | resp = check_html_get_response( | ||||
assert_template_used(resp, "error.html") | client, url, status_code=404, template_used="error.html" | ||||
) | |||||
assert re.search("Directory.*not found", resp.content.decode("utf-8")) | assert re.search("Directory.*not found", resp.content.decode("utf-8")) | ||||
@given(origin()) | @given(origin()) | ||||
def test_browse_origin_content_no_visit(client, mocker, origin): | def test_browse_origin_content_no_visit(client, mocker, origin): | ||||
mock_get_origin_visits = mocker.patch( | mock_get_origin_visits = mocker.patch( | ||||
"swh.web.common.origin_visits.get_origin_visits" | "swh.web.common.origin_visits.get_origin_visits" | ||||
) | ) | ||||
mock_get_origin_visits.return_value = [] | mock_get_origin_visits.return_value = [] | ||||
mock_archive = mocker.patch("swh.web.common.origin_visits.archive") | mock_archive = mocker.patch("swh.web.common.origin_visits.archive") | ||||
mock_archive.lookup_origin_visit_latest.return_value = None | mock_archive.lookup_origin_visit_latest.return_value = None | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-content", | "browse-origin-content", | ||||
query_params={"origin_url": origin["url"], "path": "foo"}, | query_params={"origin_url": origin["url"], "path": "foo"}, | ||||
) | ) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 404 | resp = check_html_get_response( | ||||
assert_template_used(resp, "error.html") | client, url, status_code=404, template_used="error.html" | ||||
) | |||||
assert_contains(resp, "No valid visit", status_code=404) | assert_contains(resp, "No valid visit", status_code=404) | ||||
assert not mock_get_origin_visits.called | assert not mock_get_origin_visits.called | ||||
@given(origin()) | @given(origin()) | ||||
def test_browse_origin_content_unknown_visit(client, mocker, origin): | def test_browse_origin_content_unknown_visit(client, mocker, origin): | ||||
mock_get_origin_visits = mocker.patch( | mock_get_origin_visits = mocker.patch( | ||||
"swh.web.common.origin_visits.get_origin_visits" | "swh.web.common.origin_visits.get_origin_visits" | ||||
) | ) | ||||
mock_get_origin_visits.return_value = [{"visit": 1}] | mock_get_origin_visits.return_value = [{"visit": 1}] | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-content", | "browse-origin-content", | ||||
query_params={"origin_url": origin["url"], "path": "foo", "visit_id": 2}, | query_params={"origin_url": origin["url"], "path": "foo", "visit_id": 2}, | ||||
) | ) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 404 | resp = check_html_get_response( | ||||
assert_template_used(resp, "error.html") | client, url, status_code=404, template_used="error.html" | ||||
) | |||||
assert re.search("Visit.*not found", resp.content.decode("utf-8")) | assert re.search("Visit.*not found", resp.content.decode("utf-8")) | ||||
assert mock_get_origin_visits.called | assert mock_get_origin_visits.called | ||||
@given(origin()) | @given(origin()) | ||||
def test_browse_origin_content_directory_empty_snapshot(client, mocker, origin): | def test_browse_origin_content_directory_empty_snapshot(client, mocker, origin): | ||||
mock_snapshot_archive = mocker.patch("swh.web.browse.snapshot_context.archive") | mock_snapshot_archive = mocker.patch("swh.web.browse.snapshot_context.archive") | ||||
mock_get_origin_visit_snapshot = mocker.patch( | mock_get_origin_visit_snapshot = mocker.patch( | ||||
"swh.web.browse.snapshot_context.get_origin_visit_snapshot" | "swh.web.browse.snapshot_context.get_origin_visit_snapshot" | ||||
) | ) | ||||
mock_get_origin_visit_snapshot.return_value = ([], []) | mock_get_origin_visit_snapshot.return_value = ([], []) | ||||
mock_snapshot_archive.lookup_origin.return_value = origin | mock_snapshot_archive.lookup_origin.return_value = origin | ||||
mock_snapshot_archive.lookup_snapshot_sizes.return_value = { | mock_snapshot_archive.lookup_snapshot_sizes.return_value = { | ||||
"revision": 0, | "revision": 0, | ||||
"release": 0, | "release": 0, | ||||
} | } | ||||
for browse_context in ("content", "directory"): | for browse_context in ("content", "directory"): | ||||
url = reverse( | url = reverse( | ||||
f"browse-origin-{browse_context}", | f"browse-origin-{browse_context}", | ||||
query_params={"origin_url": origin["url"], "path": "baz"}, | query_params={"origin_url": origin["url"], "path": "baz"}, | ||||
) | ) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 200 | resp = check_html_get_response( | ||||
assert_template_used(resp, f"browse/{browse_context}.html") | client, url, status_code=200, template_used=f"browse/{browse_context}.html" | ||||
) | |||||
assert re.search("snapshot.*is empty", resp.content.decode("utf-8")) | assert re.search("snapshot.*is empty", resp.content.decode("utf-8")) | ||||
assert mock_get_origin_visit_snapshot.called | assert mock_get_origin_visit_snapshot.called | ||||
assert mock_snapshot_archive.lookup_origin.called | assert mock_snapshot_archive.lookup_origin.called | ||||
assert mock_snapshot_archive.lookup_snapshot_sizes.called | assert mock_snapshot_archive.lookup_snapshot_sizes.called | ||||
@given(origin()) | @given(origin()) | ||||
def test_browse_origin_content_not_found(client, origin): | def test_browse_origin_content_not_found(client, origin): | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-content", | "browse-origin-content", | ||||
query_params={"origin_url": origin["url"], "path": "/invalid/file/path"}, | query_params={"origin_url": origin["url"], "path": "/invalid/file/path"}, | ||||
) | ) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 404 | resp = check_html_get_response( | ||||
assert_template_used(resp, "error.html") | client, url, status_code=404, template_used="error.html" | ||||
) | |||||
assert re.search("Directory entry.*not found", resp.content.decode("utf-8")) | assert re.search("Directory entry.*not found", resp.content.decode("utf-8")) | ||||
@given(origin()) | @given(origin()) | ||||
def test_browse_directory_snapshot_not_found(client, mocker, origin): | def test_browse_directory_snapshot_not_found(client, mocker, origin): | ||||
mock_get_snapshot_context = mocker.patch( | mock_get_snapshot_context = mocker.patch( | ||||
"swh.web.browse.snapshot_context.get_snapshot_context" | "swh.web.browse.snapshot_context.get_snapshot_context" | ||||
) | ) | ||||
mock_get_snapshot_context.side_effect = NotFoundExc("Snapshot not found") | mock_get_snapshot_context.side_effect = NotFoundExc("Snapshot not found") | ||||
url = reverse("browse-origin-directory", query_params={"origin_url": origin["url"]}) | url = reverse("browse-origin-directory", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 404 | resp = check_html_get_response( | ||||
assert_template_used(resp, "error.html") | client, url, status_code=404, template_used="error.html" | ||||
) | |||||
assert_contains(resp, "Snapshot not found", status_code=404) | assert_contains(resp, "Snapshot not found", status_code=404) | ||||
assert mock_get_snapshot_context.called | assert mock_get_snapshot_context.called | ||||
@given(origin()) | @given(origin()) | ||||
def test_origin_empty_snapshot(client, mocker, origin): | def test_origin_empty_snapshot(client, mocker, origin): | ||||
mock_archive = mocker.patch("swh.web.browse.snapshot_context.archive") | mock_archive = mocker.patch("swh.web.browse.snapshot_context.archive") | ||||
mock_get_origin_visit_snapshot = mocker.patch( | mock_get_origin_visit_snapshot = mocker.patch( | ||||
"swh.web.browse.snapshot_context.get_origin_visit_snapshot" | "swh.web.browse.snapshot_context.get_origin_visit_snapshot" | ||||
) | ) | ||||
mock_get_origin_visit_snapshot.return_value = ([], []) | mock_get_origin_visit_snapshot.return_value = ([], []) | ||||
mock_archive.lookup_snapshot_sizes.return_value = { | mock_archive.lookup_snapshot_sizes.return_value = { | ||||
"revision": 0, | "revision": 0, | ||||
"release": 0, | "release": 0, | ||||
} | } | ||||
mock_archive.lookup_origin.return_value = origin | mock_archive.lookup_origin.return_value = origin | ||||
url = reverse("browse-origin-directory", query_params={"origin_url": origin["url"]}) | url = reverse("browse-origin-directory", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 200 | resp = check_html_get_response( | ||||
assert_template_used(resp, "browse/directory.html") | client, url, status_code=200, template_used="browse/directory.html" | ||||
) | |||||
resp_content = resp.content.decode("utf-8") | resp_content = resp.content.decode("utf-8") | ||||
assert re.search("snapshot.*is empty", resp_content) | assert re.search("snapshot.*is empty", resp_content) | ||||
assert not re.search("swh-tr-link", resp_content) | assert not re.search("swh-tr-link", resp_content) | ||||
assert mock_get_origin_visit_snapshot.called | assert mock_get_origin_visit_snapshot.called | ||||
assert mock_archive.lookup_snapshot_sizes.called | assert mock_archive.lookup_snapshot_sizes.called | ||||
@given(new_origin()) | @given(new_origin()) | ||||
Show All 18 Lines | visit_status = OriginVisitStatus( | ||||
status="partial", | status="partial", | ||||
snapshot=snapshot.id, | snapshot=snapshot.id, | ||||
) | ) | ||||
archive_data.origin_visit_status_add([visit_status]) | archive_data.origin_visit_status_add([visit_status]) | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-directory", query_params={"origin_url": new_origin.url}, | "browse-origin-directory", query_params={"origin_url": new_origin.url}, | ||||
) | ) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 200 | resp = check_html_get_response( | ||||
assert_template_used(resp, "browse/directory.html") | client, url, status_code=200, template_used="browse/directory.html" | ||||
) | |||||
resp_content = resp.content.decode("utf-8") | resp_content = resp.content.decode("utf-8") | ||||
assert re.search("snapshot.*is empty", resp_content) | assert re.search("snapshot.*is empty", resp_content) | ||||
assert not re.search("swh-tr-link", resp_content) | assert not re.search("swh-tr-link", resp_content) | ||||
@given(origin_with_releases()) | @given(origin_with_releases()) | ||||
def test_origin_release_browse(client, archive_data, origin): | def test_origin_release_browse(client, archive_data, origin): | ||||
snapshot = archive_data.snapshot_get_latest(origin["url"]) | snapshot = archive_data.snapshot_get_latest(origin["url"]) | ||||
release = [ | release = [ | ||||
b for b in snapshot["branches"].values() if b["target_type"] == "release" | b for b in snapshot["branches"].values() if b["target_type"] == "release" | ||||
][-1] | ][-1] | ||||
release_data = archive_data.release_get(release["target"]) | release_data = archive_data.release_get(release["target"]) | ||||
revision_data = archive_data.revision_get(release_data["target"]) | revision_data = archive_data.revision_get(release_data["target"]) | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={"origin_url": origin["url"], "release": release_data["name"]}, | query_params={"origin_url": origin["url"], "release": release_data["name"]}, | ||||
) | ) | ||||
resp = client.get(url) | resp = check_html_get_response( | ||||
assert resp.status_code == 200 | client, url, status_code=200, template_used="browse/directory.html" | ||||
) | |||||
assert_contains(resp, release_data["name"]) | assert_contains(resp, release_data["name"]) | ||||
assert_contains(resp, release["target"]) | assert_contains(resp, release["target"]) | ||||
swhid_context = { | swhid_context = { | ||||
"origin": origin["url"], | "origin": origin["url"], | ||||
"visit": gen_swhid(SNAPSHOT, snapshot["id"]), | "visit": gen_swhid(SNAPSHOT, snapshot["id"]), | ||||
"anchor": gen_swhid(RELEASE, release_data["id"]), | "anchor": gen_swhid(RELEASE, release_data["id"]), | ||||
} | } | ||||
Show All 10 Lines | |||||
def test_origin_release_browse_not_found(client, origin): | def test_origin_release_browse_not_found(client, origin): | ||||
invalid_release_name = "swh-foo-bar" | invalid_release_name = "swh-foo-bar" | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={"origin_url": origin["url"], "release": invalid_release_name}, | query_params={"origin_url": origin["url"], "release": invalid_release_name}, | ||||
) | ) | ||||
resp = client.get(url) | resp = check_html_get_response( | ||||
assert resp.status_code == 404 | client, url, status_code=404, template_used="error.html" | ||||
) | |||||
assert re.search( | assert re.search( | ||||
f"Release {invalid_release_name}.*not found", resp.content.decode("utf-8") | f"Release {invalid_release_name}.*not found", resp.content.decode("utf-8") | ||||
) | ) | ||||
@given(new_origin(), unknown_revision()) | @given(new_origin(), unknown_revision()) | ||||
def test_origin_browse_directory_branch_with_non_resolvable_revision( | def test_origin_browse_directory_branch_with_non_resolvable_revision( | ||||
client, archive_data, new_origin, unknown_revision | client, archive_data, new_origin, unknown_revision | ||||
Show All 20 Lines | ): | ||||
) | ) | ||||
archive_data.origin_visit_status_add([visit_status]) | archive_data.origin_visit_status_add([visit_status]) | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={"origin_url": new_origin.url, "branch": branch_name}, | query_params={"origin_url": new_origin.url, "branch": branch_name}, | ||||
) | ) | ||||
resp = client.get(url) | resp = check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/directory.html" | |||||
assert resp.status_code == 200 | ) | ||||
assert_contains( | assert_contains( | ||||
resp, f"Revision {unknown_revision } could not be found in the archive." | resp, f"Revision {unknown_revision } could not be found in the archive." | ||||
) | ) | ||||
@given(origin()) | @given(origin()) | ||||
def test_origin_content_no_path(client, origin): | def test_origin_content_no_path(client, origin): | ||||
url = reverse("browse-origin-content", query_params={"origin_url": origin["url"]}) | url = reverse("browse-origin-content", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | resp = check_html_get_response( | ||||
client, url, status_code=400, template_used="error.html" | |||||
assert resp.status_code == 400 | ) | ||||
assert_contains( | assert_contains( | ||||
resp, "The path of a content must be given as query parameter.", status_code=400 | resp, "The path of a content must be given as query parameter.", status_code=400 | ||||
) | ) | ||||
def test_origin_views_no_url_query_parameter(client): | def test_origin_views_no_url_query_parameter(client): | ||||
for browse_context in ( | for browse_context in ( | ||||
"content", | "content", | ||||
"directory", | "directory", | ||||
"log", | "log", | ||||
"branches", | "branches", | ||||
"releases", | "releases", | ||||
"visits", | "visits", | ||||
): | ): | ||||
url = reverse(f"browse-origin-{browse_context}") | url = reverse(f"browse-origin-{browse_context}") | ||||
resp = client.get(url) | |||||
assert resp.status_code == 400 | resp = check_html_get_response( | ||||
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 | ||||
) | ) | ||||
def _origin_content_view_test_helper( | def _origin_content_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
Show All 19 Lines | ): | ||||
if visit_id: | if visit_id: | ||||
query_params["visit_id"] = visit_id | query_params["visit_id"] = visit_id | ||||
elif snapshot_id: | elif snapshot_id: | ||||
query_params["snapshot"] = snapshot_id | query_params["snapshot"] = snapshot_id | ||||
url = reverse("browse-origin-content", query_params=query_params) | url = reverse("browse-origin-content", query_params=query_params) | ||||
resp = client.get(url) | resp = check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/content.html" | |||||
assert resp.status_code == 200 | ) | ||||
assert_template_used(resp, "browse/content.html") | |||||
assert type(content["data"]) == str | assert type(content["data"]) == str | ||||
assert_contains(resp, '<code class="%s">' % content["hljs_language"]) | assert_contains(resp, '<code class="%s">' % content["hljs_language"]) | ||||
assert_contains(resp, escape(content["data"])) | assert_contains(resp, escape(content["data"])) | ||||
split_path = content_path.split("/") | split_path = content_path.split("/") | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | for release in origin_releases: | ||||
"browse-origin-content", | "browse-origin-content", | ||||
query_params={"release": release["name"], **query_params}, | query_params={"release": release["name"], **query_params}, | ||||
) | ) | ||||
assert_contains(resp, '<a href="%s">' % root_dir_release_url) | assert_contains(resp, '<a href="%s">' % root_dir_release_url) | ||||
url = reverse("browse-origin-content", query_params=query_params) | url = reverse("browse-origin-content", query_params=query_params) | ||||
resp = client.get(url) | resp = check_html_get_response( | ||||
assert resp.status_code == 200 | client, url, status_code=200, template_used="browse/content.html" | ||||
assert_template_used(resp, "browse/content.html") | ) | ||||
snapshot = archive_data.snapshot_get(origin_visit["snapshot"]) | snapshot = archive_data.snapshot_get(origin_visit["snapshot"]) | ||||
head_rev_id = archive_data.snapshot_get_head(snapshot) | head_rev_id = archive_data.snapshot_get_head(snapshot) | ||||
swhid_context = { | swhid_context = { | ||||
"origin": origin_info["url"], | "origin": origin_info["url"], | ||||
"visit": gen_swhid(SNAPSHOT, snapshot["id"]), | "visit": gen_swhid(SNAPSHOT, snapshot["id"]), | ||||
"anchor": gen_swhid(REVISION, head_rev_id), | "anchor": gen_swhid(REVISION, head_rev_id), | ||||
Show All 39 Lines | ): | ||||
else: | else: | ||||
query_params["snapshot"] = snapshot_id | query_params["snapshot"] = snapshot_id | ||||
if path: | if path: | ||||
query_params["path"] = path | query_params["path"] = path | ||||
url = reverse("browse-origin-directory", query_params=query_params) | url = reverse("browse-origin-directory", query_params=query_params) | ||||
resp = client.get(url) | resp = check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/directory.html" | |||||
assert resp.status_code == 200 | ) | ||||
assert_template_used(resp, "browse/directory.html") | |||||
assert resp.status_code == 200 | |||||
assert_template_used(resp, "browse/directory.html") | |||||
assert_contains(resp, '<td class="swh-directory">', count=len(dirs)) | assert_contains(resp, '<td class="swh-directory">', count=len(dirs)) | ||||
assert_contains(resp, '<td class="swh-content">', count=len(files)) | assert_contains(resp, '<td class="swh-content">', count=len(files)) | ||||
if timestamp: | if timestamp: | ||||
query_params["timestamp"] = format_utc_iso_date( | query_params["timestamp"] = format_utc_iso_date( | ||||
parse_iso8601_date_to_utc(timestamp).isoformat(), "%Y-%m-%dT%H:%M:%SZ" | parse_iso8601_date_to_utc(timestamp).isoformat(), "%Y-%m-%dT%H:%M:%SZ" | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | |||||
def _origin_branches_test_helper( | def _origin_branches_test_helper( | ||||
client, origin_info, origin_snapshot, snapshot_id=None | client, origin_info, origin_snapshot, 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 = client.get(url) | resp = check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/branches.html" | |||||
assert resp.status_code == 200 | ) | ||||
assert_template_used(resp, "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-origin-branches", query_params=query_params) | ||||
assert_contains(resp, f'href="{escape(origin_branches_url)}"') | assert_contains(resp, f'href="{escape(origin_branches_url)}"') | ||||
assert_contains(resp, f"Branches ({len(origin_branches)})") | assert_contains(resp, f"Branches ({len(origin_branches)})") | ||||
Show All 26 Lines | |||||
def _origin_releases_test_helper( | def _origin_releases_test_helper( | ||||
client, origin_info, origin_snapshot, snapshot_id=None | client, origin_info, origin_snapshot, 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-releases", query_params=query_params) | url = reverse("browse-origin-releases", query_params=query_params) | ||||
resp = client.get(url) | resp = check_html_get_response( | ||||
assert resp.status_code == 200 | client, url, status_code=200, template_used="browse/releases.html" | ||||
assert_template_used(resp, "browse/releases.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-origin-branches", query_params=query_params) | ||||
assert_contains(resp, f'href="{escape(origin_branches_url)}"') | assert_contains(resp, f'href="{escape(origin_branches_url)}"') | ||||
assert_contains(resp, f"Branches ({len(origin_branches)})") | assert_contains(resp, f"Branches ({len(origin_branches)})") | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | visit_status = OriginVisitStatus( | ||||
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-origin-branches", query_params={"origin_url": new_origin.url}) | ||||
resp = client.get(url) | |||||
assert resp.status_code == 200 | resp = check_html_get_response( | ||||
assert_template_used(resp, "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}"') |