Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_directory.py
Show All 25 Lines | |||||
) | ) | ||||
from swh.model.swhids import ObjectType | from swh.model.swhids import ObjectType | ||||
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_not_contains | from swh.web.tests.django_asserts import assert_contains, assert_not_contains | ||||
from swh.web.tests.strategies import ( | from swh.web.tests.strategies import ( | ||||
directory, | |||||
directory_with_subdirs, | |||||
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 | from swh.web.tests.utils import check_html_get_response | ||||
@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()) | def test_sub_directory_view(client, archive_data, directory_with_subdirs): | ||||
def test_sub_directory_view(client, archive_data, directory): | dir_content = archive_data.directory_ls(directory_with_subdirs) | ||||
dir_content = archive_data.directory_ls(directory) | |||||
subdir = random.choice([e for e in dir_content if e["type"] == "dir"]) | subdir = random.choice([e for e in dir_content if e["type"] == "dir"]) | ||||
subdir_content = archive_data.directory_ls(subdir["target"]) | subdir_content = archive_data.directory_ls(subdir["target"]) | ||||
_directory_view_checks(client, directory, subdir_content, subdir["name"]) | _directory_view_checks( | ||||
client, directory_with_subdirs, subdir_content, subdir["name"] | |||||
) | |||||
@given(empty_directory(), new_person(), new_swh_date()) | @given(new_person(), new_swh_date()) | ||||
def test_sub_directory_view_origin_context( | def test_sub_directory_view_origin_context( | ||||
client, archive_data, empty_directory, person, date | client, archive_data, empty_directory, person, date | ||||
): | ): | ||||
origin_url = "test_sub_directory_view_origin_context" | origin_url = "test_sub_directory_view_origin_context" | ||||
subdir = Directory( | subdir = Directory( | ||||
entries=( | entries=( | ||||
DirectoryEntry( | DirectoryEntry( | ||||
name=b"foo", | name=b"foo", | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | def test_directory_request_errors(client, invalid_sha1, unknown_directory): | ||||
dir_url = reverse("browse-directory", url_args={"sha1_git": unknown_directory}) | dir_url = reverse("browse-directory", url_args={"sha1_git": unknown_directory}) | ||||
check_html_get_response( | check_html_get_response( | ||||
client, dir_url, status_code=404, template_used="error.html" | client, dir_url, status_code=404, template_used="error.html" | ||||
) | ) | ||||
@given(directory()) | |||||
def test_directory_with_invalid_path(client, directory): | def test_directory_with_invalid_path(client, directory): | ||||
path = "foo/bar" | path = "foo/bar" | ||||
dir_url = reverse( | dir_url = reverse( | ||||
"browse-directory", | "browse-directory", | ||||
url_args={"sha1_git": directory}, | url_args={"sha1_git": directory}, | ||||
query_params={"path": path}, | query_params={"path": path}, | ||||
) | ) | ||||
resp = check_html_get_response( | resp = check_html_get_response( | ||||
client, dir_url, status_code=404, template_used="browse/directory.html" | client, dir_url, status_code=404, template_used="browse/directory.html" | ||||
) | ) | ||||
error_message = ( | error_message = ( | ||||
f"Directory entry with path {path} from root directory {directory} not found" | f"Directory entry with path {path} from root directory {directory} not found" | ||||
) | ) | ||||
assert_contains(resp, error_message, status_code=404) | assert_contains(resp, error_message, status_code=404) | ||||
@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 = check_html_get_response(client, url, status_code=302) | resp = check_html_get_response(client, url, 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()) | |||||
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}, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 307 Lines • Show Last 20 Lines |