Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_origin.py
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | for v in visits: | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={"origin_url": origin_url, "timestamp": vdate}, | query_params={"origin_url": origin_url, "timestamp": vdate}, | ||||
) | ) | ||||
assert_contains(resp, browse_dir_url) | assert_contains(resp, browse_dir_url) | ||||
_check_origin_link(resp, origin_url) | _check_origin_link(resp, origin_url) | ||||
def test_origin_root_directory_view(client, archive_data, swh_scheduler, origin): | @pytest.mark.django_db | ||||
def test_origin_root_directory_view( | |||||
client, staff_user, archive_data, swh_scheduler, origin | |||||
): | |||||
origin_visits = archive_data.origin_visit_get(origin["url"]) | origin_visits = archive_data.origin_visit_get(origin["url"]) | ||||
visit = origin_visits[-1] | visit = origin_visits[-1] | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
snapshot_sizes = archive_data.snapshot_count_branches(snapshot["id"]) | snapshot_sizes = archive_data.snapshot_count_branches(snapshot["id"]) | ||||
head_rev_id = archive_data.snapshot_get_head(snapshot) | head_rev_id = archive_data.snapshot_get_head(snapshot) | ||||
head_rev = archive_data.revision_get(head_rev_id) | head_rev = archive_data.revision_get(head_rev_id) | ||||
root_dir_sha1 = head_rev["directory"] | root_dir_sha1 = head_rev["directory"] | ||||
dir_content = archive_data.directory_ls(root_dir_sha1) | dir_content = archive_data.directory_ls(root_dir_sha1) | ||||
branches, releases, _ = process_snapshot_branches(snapshot) | branches, releases, _ = process_snapshot_branches(snapshot) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
visit_id=visit["visit"], | visit_id=visit["visit"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
snapshot_id=visit["snapshot"], | snapshot_id=visit["snapshot"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
visit_id=visit["visit"], | visit_id=visit["visit"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
snapshot_id=visit["snapshot"], | snapshot_id=visit["snapshot"], | ||||
) | ) | ||||
def test_origin_sub_directory_view(client, archive_data, swh_scheduler, origin): | @pytest.mark.django_db | ||||
def test_origin_sub_directory_view( | |||||
client, staff_user, archive_data, swh_scheduler, origin | |||||
): | |||||
origin_visits = archive_data.origin_visit_get(origin["url"]) | origin_visits = archive_data.origin_visit_get(origin["url"]) | ||||
visit = origin_visits[-1] | visit = origin_visits[-1] | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
snapshot_sizes = archive_data.snapshot_count_branches(snapshot["id"]) | snapshot_sizes = archive_data.snapshot_count_branches(snapshot["id"]) | ||||
head_rev_id = archive_data.snapshot_get_head(snapshot) | head_rev_id = archive_data.snapshot_get_head(snapshot) | ||||
head_rev = archive_data.revision_get(head_rev_id) | head_rev = archive_data.revision_get(head_rev_id) | ||||
root_dir_sha1 = head_rev["directory"] | root_dir_sha1 = head_rev["directory"] | ||||
subdirs = [ | subdirs = [ | ||||
e for e in archive_data.directory_ls(root_dir_sha1) if e["type"] == "dir" | e for e in archive_data.directory_ls(root_dir_sha1) if e["type"] == "dir" | ||||
] | ] | ||||
branches, releases, _ = process_snapshot_branches(snapshot) | branches, releases, _ = process_snapshot_branches(snapshot) | ||||
if len(subdirs) == 0: | if len(subdirs) == 0: | ||||
return | return | ||||
subdir = random.choice(subdirs) | subdir = random.choice(subdirs) | ||||
subdir_content = archive_data.directory_ls(subdir["target"]) | subdir_content = archive_data.directory_ls(subdir["target"]) | ||||
subdir_path = subdir["name"] | subdir_path = subdir["name"] | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
visit_id=visit["visit"], | visit_id=visit["visit"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
snapshot_id=visit["snapshot"], | snapshot_id=visit["snapshot"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
visit_id=visit["visit"], | visit_id=visit["visit"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
▲ Show 20 Lines • Show All 473 Lines • ▼ Show 20 Lines | for each_arg in url_args: | ||||
resp = check_html_get_response(client, url, status_code=301) | resp = check_html_get_response(client, url, status_code=301) | ||||
assert resp["location"] == reverse( | assert resp["location"] == reverse( | ||||
"browse-content", query_params={**each_arg, **params} | "browse-content", query_params={**each_arg, **params} | ||||
) | ) | ||||
def _origin_directory_view_test_helper( | def _origin_directory_view_test_helper( | ||||
client, | client, | ||||
staff_user, | |||||
archive_data, | archive_data, | ||||
origin_info, | origin_info, | ||||
origin_visit, | origin_visit, | ||||
snapshot_sizes, | snapshot_sizes, | ||||
origin_branches, | origin_branches, | ||||
origin_releases, | origin_releases, | ||||
root_directory_sha1, | root_directory_sha1, | ||||
directory_entries, | directory_entries, | ||||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | ): | ||||
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") | ||||
_check_origin_link(resp, origin_info["url"]) | _check_origin_link(resp, origin_info["url"]) | ||||
assert_not_contains(resp, "swh-metadata-popover") | assert_not_contains(resp, "swh-metadata-popover") | ||||
# Finally, check "Extrinsic metadata" dropdown: | |||||
origin_metadata_api_url = reverse( | |||||
"api-1-raw-extrinsic-metadata-origin-authorities", | |||||
url_args={"origin_url": origin_info["url"]}, | |||||
) | |||||
directory_metadata_api_url = reverse( | |||||
"api-1-raw-extrinsic-metadata-swhid-authorities", | |||||
url_args={"target": f"swh:1:dir:{root_directory_sha1}"}, | |||||
) | |||||
extrinsic_metadata_snippets = [ | |||||
"Extrinsic metadata", | |||||
f'<a href="{origin_metadata_api_url}" class="dropdown-item" role="button">', | |||||
f'<a href="{directory_metadata_api_url}" class="dropdown-item" role="button">', | |||||
] | |||||
client.logout() | |||||
resp = check_html_get_response( | |||||
client, url, status_code=200, template_used="browse/directory.html" | |||||
) | |||||
# None of the above should be present for logged-out users | |||||
for snippet in extrinsic_metadata_snippets: | |||||
assert_not_contains(resp, snippet) | |||||
client.force_login(staff_user) | |||||
resp = check_html_get_response( | |||||
client, url, status_code=200, template_used="browse/directory.html" | |||||
) | |||||
# But they should for staff users | |||||
for snippet in extrinsic_metadata_snippets: | |||||
assert_contains(resp, snippet) | |||||
client.logout() | |||||
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}"') | ||||
Show All 19 Lines |