Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_origin.py
Show All 39 Lines | from swh.web.tests.strategies import ( | ||||
origin_with_releases, | origin_with_releases, | ||||
release as existing_release, | release as existing_release, | ||||
unknown_revision, | unknown_revision, | ||||
) | ) | ||||
@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", url_args={"origin_url": origin["url"]}) | url = reverse("browse-origin-visits", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/origin-visits.html") | assert_template_used(resp, "browse/origin-visits.html") | ||||
url = reverse("browse-origin-visits", url_args={"origin_url": origin["url"]}) | url = reverse("browse-origin-visits", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/origin-visits.html") | 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", | ||||
url_args={"origin_url": origin["url"]}, | query_params={"origin_url": origin["url"], "timestamp": vdate}, | ||||
query_params={"timestamp": vdate}, | |||||
) | ) | ||||
assert_contains(resp, browse_dir_url) | assert_contains(resp, browse_dir_url) | ||||
@given(origin_with_multiple_visits()) | @given(origin_with_multiple_visits()) | ||||
def test_origin_content_view(client, archive_data, origin): | def test_origin_content_view(client, archive_data, origin): | ||||
origin_visits = archive_data.origin_visit_get(origin["url"]) | origin_visits = archive_data.origin_visit_get(origin["url"]) | ||||
▲ Show 20 Lines • Show All 330 Lines • ▼ Show 20 Lines | for i, branch in enumerate(snp_dict["branches"].keys()): | ||||
} | } | ||||
archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) | archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) | ||||
visit = archive_data.origin_visit_add(new_origin["url"], visit_dates[0], type="git") | visit = archive_data.origin_visit_add(new_origin["url"], visit_dates[0], type="git") | ||||
archive_data.origin_visit_update( | archive_data.origin_visit_update( | ||||
new_origin["url"], visit.visit, status="partial", snapshot=snp_dict["id"] | new_origin["url"], visit.visit, status="partial", snapshot=snp_dict["id"] | ||||
) | ) | ||||
url = reverse("browse-origin-directory", url_args={"origin_url": new_origin["url"]}) | url = reverse( | ||||
"browse-origin-directory", query_params={"origin_url": new_origin["url"]} | |||||
) | |||||
rv = client.get(url) | rv = client.get(url) | ||||
assert rv.status_code == 200 | assert rv.status_code == 200 | ||||
@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(), | ||||
Show All 13 Lines | ): | ||||
archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) | archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) | ||||
visit = archive_data.origin_visit_add(new_origin["url"], visit_dates[0], type="git") | visit = archive_data.origin_visit_add(new_origin["url"], visit_dates[0], type="git") | ||||
archive_data.origin_visit_update( | archive_data.origin_visit_update( | ||||
new_origin["url"], visit.visit, status="full", snapshot=snp_dict["id"] | new_origin["url"], visit.visit, status="full", snapshot=snp_dict["id"] | ||||
) | ) | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
url_args={"origin_url": new_origin["url"]}, | query_params={"origin_url": new_origin["url"], "branch": "invalid_branch"}, | ||||
query_params={"branch": "invalid_branch"}, | |||||
) | ) | ||||
rv = client.get(url) | rv = client.get(url) | ||||
assert rv.status_code == 404 | assert rv.status_code == 404 | ||||
@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", url_args={"origin_url": new_origin.url}) | url = reverse("browse-origin-visits", query_params={"origin_url": new_origin.url}) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
assert_template_used(resp, "error.html") | assert_template_used(resp, "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 = [] | ||||
url = reverse("browse-origin-directory", url_args={"origin_url": origin["url"]}) | url = reverse("browse-origin-directory", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
assert_template_used(resp, "error.html") | assert_template_used(resp, "error.html") | ||||
assert_contains(resp, "No visit", status_code=404) | assert_contains(resp, "No visit", status_code=404) | ||||
assert mock_get_origin_visits.called | assert 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", | ||||
url_args={"origin_url": origin["url"]}, | query_params={"origin_url": origin["url"], "visit_id": 2}, | ||||
query_params={"visit_id": 2}, | |||||
) | ) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
assert_template_used(resp, "error.html") | assert_template_used(resp, "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", | ||||
url_args={"origin_url": origin["url"]}, | query_params={"origin_url": origin["url"], "path": "/invalid/dir/path/"}, | ||||
query_params={"path": "/invalid/dir/path/"}, | |||||
) | ) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
assert_template_used(resp, "error.html") | assert_template_used(resp, "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 = [] | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-content", | "browse-origin-content", | ||||
url_args={"origin_url": origin["url"]}, | query_params={"origin_url": origin["url"], "path": "foo"}, | ||||
query_params={"path": "foo"}, | |||||
) | ) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
assert_template_used(resp, "error.html") | assert_template_used(resp, "error.html") | ||||
assert_contains(resp, "No visit", status_code=404) | assert_contains(resp, "No visit", status_code=404) | ||||
assert mock_get_origin_visits.called | assert 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", | ||||
url_args={"origin_url": origin["url"]}, | query_params={"origin_url": origin["url"], "path": "foo", "visit_id": 2}, | ||||
query_params={"path": "foo", "visit_id": 2}, | |||||
) | ) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
assert_template_used(resp, "error.html") | assert_template_used(resp, "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 | ||||
Show All 9 Lines | mock_snapshot_service.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}", | ||||
url_args={"origin_url": origin["url"]}, | query_params={"origin_url": origin["url"], "path": "baz"}, | ||||
query_params={"path": "baz"}, | |||||
) | ) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, f"browse/{browse_context}.html") | assert_template_used(resp, 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_service.lookup_origin.called | assert mock_snapshot_service.lookup_origin.called | ||||
assert mock_snapshot_service.lookup_snapshot_sizes.called | assert mock_snapshot_service.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", | ||||
url_args={"origin_url": origin["url"]}, | query_params={"origin_url": origin["url"], "path": "/invalid/file/path"}, | ||||
query_params={"path": "/invalid/file/path"}, | |||||
) | ) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
assert_template_used(resp, "error.html") | assert_template_used(resp, "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", url_args={"origin_url": origin["url"]}) | url = reverse("browse-origin-directory", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
assert_template_used(resp, "error.html") | assert_template_used(resp, "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_service = mocker.patch("swh.web.browse.snapshot_context.service") | mock_service = mocker.patch("swh.web.browse.snapshot_context.service") | ||||
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_service.lookup_snapshot_sizes.return_value = { | mock_service.lookup_snapshot_sizes.return_value = { | ||||
"revision": 0, | "revision": 0, | ||||
"release": 0, | "release": 0, | ||||
} | } | ||||
mock_service.lookup_origin.return_value = origin | mock_service.lookup_origin.return_value = origin | ||||
url = reverse("browse-origin-directory", url_args={"origin_url": origin["url"]}) | url = reverse("browse-origin-directory", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/directory.html") | assert_template_used(resp, "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_service.lookup_snapshot_sizes.called | assert mock_service.lookup_snapshot_sizes.called | ||||
@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): | ||||
# for swh.web.browse.snapshot_context.get_snapshot_content to only return one branch | # for swh.web.browse.snapshot_context.get_snapshot_content to only return one branch | ||||
config = get_config() | config = get_config() | ||||
snapshot_max_size = int(config["snapshot_content_max_size"]) | snapshot_max_size = int(config["snapshot_content_max_size"]) | ||||
config["snapshot_content_max_size"] = 1 | config["snapshot_content_max_size"] = 1 | ||||
try: | try: | ||||
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"]) | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
url_args={"origin_url": origin["url"]}, | query_params={"origin_url": origin["url"], "release": release_data["name"]}, | ||||
query_params={"release": release_data["name"]}, | |||||
) | ) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_contains(resp, release_data["name"]) | assert_contains(resp, release_data["name"]) | ||||
assert_contains(resp, release["target"]) | assert_contains(resp, release["target"]) | ||||
finally: | finally: | ||||
config["snapshot_content_max_size"] = snapshot_max_size | config["snapshot_content_max_size"] = snapshot_max_size | ||||
@given(origin_with_releases()) | @given(origin_with_releases()) | ||||
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", | ||||
url_args={"origin_url": origin["url"]}, | query_params={"origin_url": origin["url"], "release": invalid_release_name}, | ||||
query_params={"release": invalid_release_name}, | |||||
) | ) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
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") | ||||
) | ) | ||||
Show All 14 Lines | ): | ||||
archive_data.snapshot_add([snapshot]) | archive_data.snapshot_add([snapshot]) | ||||
visit = archive_data.origin_visit_add(new_origin["url"], datetime.now(), type="git") | visit = archive_data.origin_visit_add(new_origin["url"], datetime.now(), type="git") | ||||
archive_data.origin_visit_update( | archive_data.origin_visit_update( | ||||
new_origin["url"], visit.visit, status="full", snapshot=snapshot.id | new_origin["url"], visit.visit, status="full", snapshot=snapshot.id | ||||
) | ) | ||||
url = reverse( | url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
url_args={"origin_url": new_origin["url"]}, | query_params={"origin_url": new_origin["url"], "branch": branch_name}, | ||||
query_params={"branch": branch_name}, | |||||
) | ) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | 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", url_args={"origin_url": origin["url"]}) | url = reverse("browse-origin-content", query_params={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 400 | 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): | |||||
for browse_context in ( | |||||
"content", | |||||
"directory", | |||||
"log", | |||||
"branches", | |||||
"releases", | |||||
"visits", | |||||
): | |||||
url = reverse(f"browse-origin-{browse_context}") | |||||
resp = client.get(url) | |||||
assert resp.status_code == 400 | |||||
assert_contains( | |||||
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, | ||||
origin_info, | origin_info, | ||||
origin_visits, | origin_visits, | ||||
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, | ||||
): | ): | ||||
content_path = "/".join(content["path"].split("/")[1:]) | content_path = "/".join(content["path"].split("/")[1:]) | ||||
url_args = {"origin_url": origin_info["url"]} | |||||
if not visit_id: | if not visit_id: | ||||
visit_id = origin_visits[-1]["visit"] | visit_id = origin_visits[-1]["visit"] | ||||
query_params = {"path": content_path} | query_params = {"origin_url": origin_info["url"], "path": content_path} | ||||
if timestamp: | if timestamp: | ||||
query_params["timestamp"] = timestamp | query_params["timestamp"] = timestamp | ||||
if visit_id: | if visit_id: | ||||
query_params["visit_id"] = visit_id | query_params["visit_id"] = visit_id | ||||
url = reverse("browse-origin-content", url_args=url_args, query_params=query_params) | url = reverse("browse-origin-content", query_params=query_params) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/content.html") | assert_template_used(resp, "browse/content.html") | ||||
assert type(content["data"]) == str | assert type(content["data"]) == str | ||||
Show All 9 Lines | ): | ||||
del query_params["path"] | del query_params["path"] | ||||
if timestamp: | if timestamp: | ||||
query_params["timestamp"] = format_utc_iso_date( | query_params["timestamp"] = format_utc_iso_date( | ||||
parse_timestamp(timestamp).isoformat(), "%Y-%m-%dT%H:%M:%SZ" | parse_timestamp(timestamp).isoformat(), "%Y-%m-%dT%H:%M:%SZ" | ||||
) | ) | ||||
root_dir_url = reverse( | root_dir_url = reverse("browse-origin-directory", query_params=query_params) | ||||
"browse-origin-directory", url_args=url_args, query_params=query_params | |||||
) | |||||
assert_contains(resp, '<li class="swh-path">', count=len(path_info) + 1) | assert_contains(resp, '<li class="swh-path">', count=len(path_info) + 1) | ||||
assert_contains(resp, '<a href="%s">%s</a>' % (root_dir_url, root_dir_sha1[:7])) | assert_contains(resp, '<a href="%s">%s</a>' % (root_dir_url, root_dir_sha1[:7])) | ||||
for p in path_info: | for p in path_info: | ||||
query_params["path"] = p["path"] | query_params["path"] = p["path"] | ||||
dir_url = reverse( | dir_url = reverse("browse-origin-directory", query_params=query_params) | ||||
"browse-origin-directory", url_args=url_args, query_params=query_params | |||||
) | |||||
assert_contains(resp, '<a href="%s">%s</a>' % (dir_url, p["name"])) | assert_contains(resp, '<a href="%s">%s</a>' % (dir_url, p["name"])) | ||||
assert_contains(resp, "<li>%s</li>" % filename) | assert_contains(resp, "<li>%s</li>" % filename) | ||||
query_string = "sha1_git:" + content["sha1_git"] | query_string = "sha1_git:" + content["sha1_git"] | ||||
url_raw = reverse( | url_raw = reverse( | ||||
"browse-content-raw", | "browse-content-raw", | ||||
url_args={"query_string": query_string}, | url_args={"query_string": query_string}, | ||||
query_params={"filename": filename}, | query_params={"filename": filename}, | ||||
) | ) | ||||
assert_contains(resp, url_raw) | assert_contains(resp, url_raw) | ||||
if "path" in query_params: | if "path" in query_params: | ||||
del query_params["path"] | del query_params["path"] | ||||
origin_branches_url = reverse( | origin_branches_url = reverse("browse-origin-branches", query_params=query_params) | ||||
"browse-origin-branches", url_args=url_args, query_params=query_params | |||||
) | |||||
assert_contains( | assert_contains( | ||||
resp, | resp, | ||||
'<a href="%s">Branches (%s)</a>' | '<a href="%s">Branches (%s)</a>' | ||||
% (escape(origin_branches_url), len(origin_branches)), | % (escape(origin_branches_url), len(origin_branches)), | ||||
) | ) | ||||
origin_releases_url = reverse( | origin_releases_url = reverse("browse-origin-releases", query_params=query_params) | ||||
"browse-origin-releases", url_args=url_args, query_params=query_params | |||||
) | |||||
assert_contains( | assert_contains( | ||||
resp, | resp, | ||||
'<a href="%s">Releases (%s)</a>' | '<a href="%s">Releases (%s)</a>' | ||||
% (escape(origin_releases_url), len(origin_releases)), | % (escape(origin_releases_url), len(origin_releases)), | ||||
) | ) | ||||
assert_contains(resp, '<li class="swh-branch">', count=len(origin_branches)) | assert_contains(resp, '<li class="swh-branch">', count=len(origin_branches)) | ||||
query_params["path"] = content_path | query_params["path"] = content_path | ||||
for branch in origin_branches: | for branch in origin_branches: | ||||
query_params["branch"] = branch["name"] | query_params["branch"] = branch["name"] | ||||
root_dir_branch_url = reverse( | root_dir_branch_url = reverse( | ||||
"browse-origin-content", url_args=url_args, query_params=query_params | "browse-origin-content", query_params=query_params | ||||
) | ) | ||||
assert_contains(resp, '<a href="%s">' % root_dir_branch_url) | assert_contains(resp, '<a href="%s">' % root_dir_branch_url) | ||||
assert_contains(resp, '<li class="swh-release">', count=len(origin_releases)) | assert_contains(resp, '<li class="swh-release">', count=len(origin_releases)) | ||||
query_params["branch"] = None | query_params["branch"] = None | ||||
for release in origin_releases: | for release in origin_releases: | ||||
query_params["release"] = release["name"] | query_params["release"] = release["name"] | ||||
root_dir_release_url = reverse( | root_dir_release_url = reverse( | ||||
"browse-origin-content", url_args=url_args, query_params=query_params | "browse-origin-content", query_params=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", url_args=url_args, query_params=query_params) | url = reverse("browse-origin-content", query_params=query_params) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/content.html") | assert_template_used(resp, "browse/content.html") | ||||
swh_cnt_id = get_swh_persistent_id("content", content["sha1_git"]) | swh_cnt_id = get_swh_persistent_id("content", content["sha1_git"]) | ||||
swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id}) | swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id}) | ||||
assert_contains(resp, swh_cnt_id) | assert_contains(resp, swh_cnt_id) | ||||
Show All 15 Lines | def _origin_directory_view_test_helper( | ||||
path=None, | path=None, | ||||
): | ): | ||||
dirs = [e for e in directory_entries if e["type"] in ("dir", "rev")] | dirs = [e for e in directory_entries if e["type"] in ("dir", "rev")] | ||||
files = [e for e in directory_entries if e["type"] == "file"] | files = [e for e in directory_entries if e["type"] == "file"] | ||||
if not visit_id: | if not visit_id: | ||||
visit_id = origin_visits[-1]["visit"] | visit_id = origin_visits[-1]["visit"] | ||||
url_args = {"origin_url": origin_info["url"]} | query_params = {"origin_url": origin_info["url"]} | ||||
query_params = {} | |||||
if timestamp: | if timestamp: | ||||
query_params["timestamp"] = timestamp | query_params["timestamp"] = timestamp | ||||
else: | else: | ||||
query_params["visit_id"] = visit_id | query_params["visit_id"] = visit_id | ||||
if path: | if path: | ||||
query_params["path"] = path | query_params["path"] = path | ||||
url = reverse( | url = reverse("browse-origin-directory", query_params=query_params) | ||||
"browse-origin-directory", url_args=url_args, query_params=query_params | |||||
) | |||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/directory.html") | assert_template_used(resp, "browse/directory.html") | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/directory.html") | assert_template_used(resp, "browse/directory.html") | ||||
Show All 9 Lines | ): | ||||
for d in dirs: | for d in dirs: | ||||
if d["type"] == "rev": | if d["type"] == "rev": | ||||
dir_url = reverse("browse-revision", url_args={"sha1_git": d["target"]}) | dir_url = reverse("browse-revision", url_args={"sha1_git": d["target"]}) | ||||
else: | else: | ||||
dir_path = d["name"] | dir_path = d["name"] | ||||
if path: | if path: | ||||
dir_path = "%s/%s" % (path, d["name"]) | dir_path = "%s/%s" % (path, d["name"]) | ||||
query_params["path"] = dir_path | query_params["path"] = dir_path | ||||
dir_url = reverse( | dir_url = reverse("browse-origin-directory", query_params=query_params,) | ||||
"browse-origin-directory", url_args=url_args, query_params=query_params, | |||||
) | |||||
assert_contains(resp, dir_url) | assert_contains(resp, dir_url) | ||||
for f in files: | for f in files: | ||||
file_path = f["name"] | file_path = f["name"] | ||||
if path: | if path: | ||||
file_path = "%s/%s" % (path, f["name"]) | file_path = "%s/%s" % (path, f["name"]) | ||||
query_params["path"] = file_path | query_params["path"] = file_path | ||||
file_url = reverse( | file_url = reverse("browse-origin-content", query_params=query_params) | ||||
"browse-origin-content", url_args=url_args, query_params=query_params | |||||
) | |||||
assert_contains(resp, file_url) | assert_contains(resp, file_url) | ||||
if "path" in query_params: | if "path" in query_params: | ||||
del query_params["path"] | del query_params["path"] | ||||
root_dir_branch_url = reverse( | root_dir_branch_url = reverse("browse-origin-directory", query_params=query_params) | ||||
"browse-origin-directory", url_args=url_args, query_params=query_params | |||||
) | |||||
nb_bc_paths = 1 | nb_bc_paths = 1 | ||||
if path: | if path: | ||||
nb_bc_paths = len(path.split("/")) + 1 | nb_bc_paths = len(path.split("/")) + 1 | ||||
assert_contains(resp, '<li class="swh-path">', count=nb_bc_paths) | assert_contains(resp, '<li class="swh-path">', count=nb_bc_paths) | ||||
assert_contains( | assert_contains( | ||||
resp, '<a href="%s">%s</a>' % (root_dir_branch_url, root_directory_sha1[:7]) | resp, '<a href="%s">%s</a>' % (root_dir_branch_url, root_directory_sha1[:7]) | ||||
) | ) | ||||
origin_branches_url = reverse( | origin_branches_url = reverse("browse-origin-branches", query_params=query_params) | ||||
"browse-origin-branches", url_args=url_args, query_params=query_params | |||||
) | |||||
assert_contains( | assert_contains( | ||||
resp, | resp, | ||||
'<a href="%s">Branches (%s)</a>' % (origin_branches_url, len(origin_branches)), | '<a href="%s">Branches (%s)</a>' | ||||
% (escape(origin_branches_url), len(origin_branches)), | |||||
) | ) | ||||
origin_releases_url = reverse( | origin_releases_url = reverse("browse-origin-releases", query_params=query_params) | ||||
"browse-origin-releases", url_args=url_args, query_params=query_params | |||||
) | |||||
nb_releases = len(origin_releases) | nb_releases = len(origin_releases) | ||||
if nb_releases > 0: | if nb_releases > 0: | ||||
assert_contains( | assert_contains( | ||||
resp, '<a href="%s">Releases (%s)</a>' % (origin_releases_url, nb_releases) | resp, | ||||
'<a href="%s">Releases (%s)</a>' | |||||
% (escape(origin_releases_url), nb_releases), | |||||
) | ) | ||||
if path: | if path: | ||||
query_params["path"] = path | query_params["path"] = path | ||||
assert_contains(resp, '<li class="swh-branch">', count=len(origin_branches)) | assert_contains(resp, '<li class="swh-branch">', count=len(origin_branches)) | ||||
for branch in origin_branches: | for branch in origin_branches: | ||||
query_params["branch"] = branch["name"] | query_params["branch"] = branch["name"] | ||||
root_dir_branch_url = reverse( | root_dir_branch_url = reverse( | ||||
"browse-origin-directory", url_args=url_args, query_params=query_params | "browse-origin-directory", query_params=query_params | ||||
) | ) | ||||
assert_contains(resp, '<a href="%s">' % root_dir_branch_url) | assert_contains(resp, '<a href="%s">' % root_dir_branch_url) | ||||
assert_contains(resp, '<li class="swh-release">', count=len(origin_releases)) | assert_contains(resp, '<li class="swh-release">', count=len(origin_releases)) | ||||
query_params["branch"] = None | query_params["branch"] = None | ||||
for release in origin_releases: | for release in origin_releases: | ||||
query_params["release"] = release["name"] | query_params["release"] = release["name"] | ||||
root_dir_release_url = reverse( | root_dir_release_url = reverse( | ||||
"browse-origin-directory", url_args=url_args, query_params=query_params | "browse-origin-directory", query_params=query_params | ||||
) | ) | ||||
assert_contains(resp, '<a href="%s">' % root_dir_release_url) | assert_contains(resp, '<a href="%s">' % root_dir_release_url) | ||||
assert_contains(resp, "vault-cook-directory") | assert_contains(resp, "vault-cook-directory") | ||||
assert_contains(resp, "vault-cook-revision") | assert_contains(resp, "vault-cook-revision") | ||||
swh_dir_id = get_swh_persistent_id("directory", directory_entries[0]["dir_id"]) | swh_dir_id = get_swh_persistent_id("directory", directory_entries[0]["dir_id"]) | ||||
swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id}) | swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id}) | ||||
assert_contains(resp, swh_dir_id) | assert_contains(resp, swh_dir_id) | ||||
assert_contains(resp, swh_dir_id_url) | assert_contains(resp, swh_dir_id_url) | ||||
assert_contains(resp, "swh-take-new-snapshot") | assert_contains(resp, "swh-take-new-snapshot") | ||||
def _origin_branches_test_helper(client, origin_info, origin_snapshot): | def _origin_branches_test_helper(client, origin_info, origin_snapshot): | ||||
url_args = {"origin_url": origin_info["url"]} | query_params = {"origin_url": origin_info["url"]} | ||||
url = reverse("browse-origin-branches", url_args=url_args) | url = reverse("browse-origin-branches", query_params=query_params) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/branches.html") | 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", url_args=url_args) | origin_branches_url = reverse("browse-origin-branches", query_params=query_params) | ||||
assert_contains( | assert_contains( | ||||
resp, | resp, | ||||
'<a href="%s">Branches (%s)</a>' % (origin_branches_url, len(origin_branches)), | '<a href="%s">Branches (%s)</a>' % (origin_branches_url, len(origin_branches)), | ||||
) | ) | ||||
origin_releases_url = reverse("browse-origin-releases", url_args=url_args) | 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( | assert_contains( | ||||
resp, '<a href="%s">Releases (%s)</a>' % (origin_releases_url, nb_releases) | resp, '<a href="%s">Releases (%s)</a>' % (origin_releases_url, nb_releases) | ||||
) | ) | ||||
assert_contains(resp, '<tr class="swh-branch-entry', count=len(origin_branches)) | assert_contains(resp, '<tr class="swh-branch-entry', count=len(origin_branches)) | ||||
for branch in origin_branches: | for branch in origin_branches: | ||||
browse_branch_url = reverse( | browse_branch_url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
url_args={"origin_url": origin_info["url"]}, | query_params={"origin_url": origin_info["url"], "branch": branch["name"]}, | ||||
query_params={"branch": branch["name"]}, | |||||
) | ) | ||||
assert_contains(resp, '<a href="%s">' % escape(browse_branch_url)) | assert_contains(resp, '<a href="%s">' % escape(browse_branch_url)) | ||||
browse_revision_url = reverse( | browse_revision_url = reverse( | ||||
"browse-revision", | "browse-revision", | ||||
url_args={"sha1_git": branch["revision"]}, | url_args={"sha1_git": branch["revision"]}, | ||||
query_params={"origin": origin_info["url"]}, | query_params={"origin": origin_info["url"]}, | ||||
) | ) | ||||
assert_contains(resp, '<a href="%s">' % escape(browse_revision_url)) | assert_contains(resp, '<a href="%s">' % escape(browse_revision_url)) | ||||
def _origin_releases_test_helper(client, origin_info, origin_snapshot): | def _origin_releases_test_helper(client, origin_info, origin_snapshot): | ||||
url_args = {"origin_url": origin_info["url"]} | query_params = {"origin_url": origin_info["url"]} | ||||
url = reverse("browse-origin-releases", url_args=url_args) | url = reverse("browse-origin-releases", query_params=query_params) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "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", url_args=url_args) | origin_branches_url = reverse("browse-origin-branches", query_params=query_params) | ||||
assert_contains( | assert_contains( | ||||
resp, | resp, | ||||
'<a href="%s">Branches (%s)</a>' % (origin_branches_url, len(origin_branches)), | '<a href="%s">Branches (%s)</a>' % (origin_branches_url, len(origin_branches)), | ||||
) | ) | ||||
origin_releases_url = reverse("browse-origin-releases", url_args=url_args) | 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( | assert_contains( | ||||
resp, '<a href="%s">Releases (%s)</a>' % (origin_releases_url, nb_releases) | resp, '<a href="%s">Releases (%s)</a>' % (origin_releases_url, nb_releases) | ||||
) | ) | ||||
assert_contains(resp, '<tr class="swh-release-entry', count=nb_releases) | assert_contains(resp, '<tr class="swh-release-entry', count=nb_releases) | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | ): | ||||
} | } | ||||
new_origin = archive_data.origin_add([new_origin])[0] | new_origin = archive_data.origin_add([new_origin])[0] | ||||
archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) | archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) | ||||
visit = archive_data.origin_visit_add(new_origin["url"], visit_dates[0], type="git") | visit = archive_data.origin_visit_add(new_origin["url"], visit_dates[0], type="git") | ||||
archive_data.origin_visit_update( | archive_data.origin_visit_update( | ||||
new_origin["url"], visit.visit, status="full", snapshot=snp_dict["id"] | new_origin["url"], visit.visit, status="full", snapshot=snp_dict["id"] | ||||
) | ) | ||||
url = reverse("browse-origin-branches", url_args={"origin_url": new_origin["url"]}) | url = reverse( | ||||
"browse-origin-branches", query_params={"origin_url": new_origin["url"]} | |||||
) | |||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/branches.html") | assert_template_used(resp, "browse/branches.html") | ||||
assert_contains(resp, '<ul class="pagination') | assert_contains(resp, '<ul class="pagination') |