Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_directory.py
Show All 23 Lines | from swh.model.model import ( | ||||
SnapshotBranch, | SnapshotBranch, | ||||
TargetType, | TargetType, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
from swh.storage.utils import now | from swh.storage.utils import now | ||||
from swh.web.browse.snapshot_context import process_snapshot_branches | from swh.web.browse.snapshot_context import process_snapshot_branches | ||||
from swh.web.common.identifiers import gen_swhid | from swh.web.common.identifiers import gen_swhid | ||||
from swh.web.common.utils import gen_path_info, reverse | from swh.web.common.utils import gen_path_info, reverse | ||||
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 ( | ||||
directory, | directory, | ||||
directory_with_subdirs, | directory_with_subdirs, | ||||
empty_directory, | empty_directory, | ||||
invalid_sha1, | invalid_sha1, | ||||
new_person, | new_person, | ||||
new_swh_date, | new_swh_date, | ||||
origin_with_multiple_visits, | origin_with_multiple_visits, | ||||
unknown_directory, | unknown_directory, | ||||
) | ) | ||||
from swh.web.tests.utils import check_html_get_response | |||||
@given(directory()) | @given(directory()) | ||||
def test_root_directory_view(client, archive_data, directory): | def test_root_directory_view(client, archive_data, directory): | ||||
_directory_view_checks(client, directory, archive_data.directory_ls(directory)) | _directory_view_checks(client, directory, archive_data.directory_ls(directory)) | ||||
@given(directory_with_subdirs()) | @given(directory_with_subdirs()) | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | _directory_view_checks( | ||||
hash_to_hex(revision.id), | hash_to_hex(revision.id), | ||||
) | ) | ||||
@given(invalid_sha1(), unknown_directory()) | @given(invalid_sha1(), unknown_directory()) | ||||
def test_directory_request_errors(client, invalid_sha1, unknown_directory): | def test_directory_request_errors(client, invalid_sha1, unknown_directory): | ||||
dir_url = reverse("browse-directory", url_args={"sha1_git": invalid_sha1}) | dir_url = reverse("browse-directory", url_args={"sha1_git": invalid_sha1}) | ||||
resp = client.get(dir_url) | check_html_get_response( | ||||
assert resp.status_code == 400 | client, dir_url, status_code=400, template_used="error.html" | ||||
assert_template_used(resp, "error.html") | ) | ||||
dir_url = reverse("browse-directory", url_args={"sha1_git": unknown_directory}) | dir_url = reverse("browse-directory", url_args={"sha1_git": unknown_directory}) | ||||
resp = client.get(dir_url) | check_html_get_response( | ||||
assert resp.status_code == 404 | client, dir_url, status_code=404, template_used="error.html" | ||||
assert_template_used(resp, "error.html") | ) | ||||
@given(directory()) | @given(directory()) | ||||
def test_directory_uppercase(client, directory): | def test_directory_uppercase(client, directory): | ||||
url = reverse( | url = reverse( | ||||
"browse-directory-uppercase-checksum", url_args={"sha1_git": directory.upper()} | "browse-directory-uppercase-checksum", url_args={"sha1_git": directory.upper()} | ||||
) | ) | ||||
resp = client.get(url) | resp = check_html_get_response(client, url, status_code=302) | ||||
assert resp.status_code == 302 | |||||
redirect_url = reverse("browse-directory", url_args={"sha1_git": directory}) | redirect_url = reverse("browse-directory", url_args={"sha1_git": directory}) | ||||
assert resp["location"] == redirect_url | assert resp["location"] == redirect_url | ||||
@given(directory()) | @given(directory()) | ||||
def test_permalink_box_context(client, tests_data, directory): | def test_permalink_box_context(client, tests_data, directory): | ||||
origin_url = random.choice(tests_data["origins"])["url"] | origin_url = random.choice(tests_data["origins"])["url"] | ||||
url = reverse( | url = reverse( | ||||
"browse-directory", | "browse-directory", | ||||
url_args={"sha1_git": directory}, | url_args={"sha1_git": directory}, | ||||
query_params={"origin_url": origin_url}, | query_params={"origin_url": origin_url}, | ||||
) | ) | ||||
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(resp, 'id="swhid-context-option-directory"') | assert_contains(resp, 'id="swhid-context-option-directory"') | ||||
@given(origin_with_multiple_visits()) | @given(origin_with_multiple_visits()) | ||||
def test_directory_origin_snapshot_branch_browse(client, archive_data, origin): | def test_directory_origin_snapshot_branch_browse(client, archive_data, origin): | ||||
visits = archive_data.origin_visit_get(origin["url"]) | visits = archive_data.origin_visit_get(origin["url"]) | ||||
visit = random.choice(visits) | visit = random.choice(visits) | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
Show All 12 Lines | url = reverse( | ||||
query_params={ | query_params={ | ||||
"origin_url": origin["url"], | "origin_url": origin["url"], | ||||
"snapshot": snapshot["id"], | "snapshot": snapshot["id"], | ||||
"branch": branch_info["name"], | "branch": branch_info["name"], | ||||
"path": directory_subdir["name"], | "path": directory_subdir["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_template_used(resp, "browse/directory.html") | |||||
_check_origin_snapshot_related_html(resp, origin, snapshot, branches, releases) | _check_origin_snapshot_related_html(resp, origin, snapshot, branches, releases) | ||||
assert_contains(resp, directory_subdir["name"]) | assert_contains(resp, directory_subdir["name"]) | ||||
assert_contains(resp, f"Branch: <strong>{branch_info['name']}</strong>") | assert_contains(resp, f"Branch: <strong>{branch_info['name']}</strong>") | ||||
dir_swhid = gen_swhid( | dir_swhid = gen_swhid( | ||||
DIRECTORY, | DIRECTORY, | ||||
directory_subdir["target"], | directory_subdir["target"], | ||||
metadata={ | metadata={ | ||||
Show All 36 Lines | url = reverse( | ||||
query_params={ | query_params={ | ||||
"origin_url": origin["url"], | "origin_url": origin["url"], | ||||
"snapshot": snapshot["id"], | "snapshot": snapshot["id"], | ||||
"release": release_info["name"], | "release": release_info["name"], | ||||
"path": directory_subdir["name"], | "path": directory_subdir["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_template_used(resp, "browse/directory.html") | ) | ||||
_check_origin_snapshot_related_html(resp, origin, snapshot, branches, releases) | _check_origin_snapshot_related_html(resp, origin, snapshot, branches, releases) | ||||
assert_contains(resp, directory_subdir["name"]) | assert_contains(resp, directory_subdir["name"]) | ||||
assert_contains(resp, f"Release: <strong>{release_info['name']}</strong>") | assert_contains(resp, f"Release: <strong>{release_info['name']}</strong>") | ||||
dir_swhid = gen_swhid( | dir_swhid = gen_swhid( | ||||
DIRECTORY, | DIRECTORY, | ||||
directory_subdir["target"], | directory_subdir["target"], | ||||
metadata={ | metadata={ | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | url = reverse( | ||||
url_args=url_args, | url_args=url_args, | ||||
query_params={**query_params, "path": path}, | query_params={**query_params, "path": path}, | ||||
) | ) | ||||
root_dir_url = reverse( | root_dir_url = reverse( | ||||
"browse-directory", url_args=url_args, query_params=query_params, | "browse-directory", url_args=url_args, 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_contains( | assert_contains( | ||||
resp, '<a href="' + root_dir_url + '">' + root_directory_sha1[:7] + "</a>", | resp, '<a href="' + root_dir_url + '">' + root_directory_sha1[:7] + "</a>", | ||||
) | ) | ||||
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)) | ||||
for d in dirs: | for d in dirs: | ||||
if d["type"] == "rev": | if d["type"] == "rev": | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |