Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_origin.py
Show All 23 Lines | |||||
) | ) | ||||
from swh.web.browse.snapshot_context import process_snapshot_branches | from swh.web.browse.snapshot_context import process_snapshot_branches | ||||
from swh.web.common.exc import NotFoundExc | from swh.web.common.exc import NotFoundExc | ||||
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 ( | ||||
reverse, | reverse, | ||||
gen_path_info, | gen_path_info, | ||||
format_utc_iso_date, | format_utc_iso_date, | ||||
parse_timestamp, | parse_iso8601_date_to_utc, | ||||
) | ) | ||||
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, assert_template_used | ||||
from swh.web.tests.strategies import ( | from swh.web.tests.strategies import ( | ||||
origin, | origin, | ||||
origin_with_multiple_visits, | origin_with_multiple_visits, | ||||
new_origin, | new_origin, | ||||
new_snapshot, | new_snapshot, | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | _origin_content_view_test_helper( | ||||
origin_visits[-1], | origin_visits[-1], | ||||
tdata["branches"], | tdata["branches"], | ||||
tdata["releases"], | tdata["releases"], | ||||
tdata["root_dir_sha1"], | tdata["root_dir_sha1"], | ||||
tdata["content"], | tdata["content"], | ||||
timestamp=tdata["visit"]["date"], | timestamp=tdata["visit"]["date"], | ||||
) | ) | ||||
visit_unix_ts = parse_timestamp(tdata["visit"]["date"]).timestamp() | |||||
visit_unix_ts = int(visit_unix_ts) | |||||
_origin_content_view_test_helper( | |||||
client, | |||||
archive_data, | |||||
origin, | |||||
origin_visits[-1], | |||||
tdata["branches"], | |||||
tdata["releases"], | |||||
tdata["root_dir_sha1"], | |||||
tdata["content"], | |||||
timestamp=visit_unix_ts, | |||||
) | |||||
_origin_content_view_test_helper( | _origin_content_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
origin_visits[-1], | origin_visits[-1], | ||||
tdata["branches"], | tdata["branches"], | ||||
tdata["releases"], | tdata["releases"], | ||||
tdata["root_dir_sha1"], | tdata["root_dir_sha1"], | ||||
Show All 34 Lines | def test_origin_root_directory_view(client, archive_data, origin): | ||||
visit = origin_visits[-1] | visit = origin_visits[-1] | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
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) | ||||
visit_unix_ts = parse_timestamp(visit["date"]).timestamp() | |||||
visit_unix_ts = int(visit_unix_ts) | |||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
Show All 17 Lines | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
timestamp=visit_unix_ts, | |||||
) | |||||
_origin_directory_view_test_helper( | |||||
client, | |||||
archive_data, | |||||
origin, | |||||
visit, | |||||
branches, | |||||
releases, | |||||
root_dir_sha1, | |||||
dir_content, | |||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
Show All 31 Lines | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
timestamp=visit_unix_ts, | |||||
) | |||||
_origin_directory_view_test_helper( | |||||
client, | |||||
archive_data, | |||||
origin, | |||||
visit, | |||||
branches, | |||||
releases, | |||||
root_dir_sha1, | |||||
dir_content, | |||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
Show All 13 Lines | def test_origin_sub_directory_view(client, archive_data, origin): | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
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) | ||||
visit_unix_ts = parse_timestamp(visit["date"]).timestamp() | |||||
visit_unix_ts = int(visit_unix_ts) | |||||
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"] | ||||
Show All 27 Lines | _origin_directory_view_test_helper( | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
timestamp=visit_unix_ts, | |||||
) | |||||
_origin_directory_view_test_helper( | |||||
client, | |||||
archive_data, | |||||
origin, | |||||
visit, | |||||
branches, | |||||
releases, | |||||
root_dir_sha1, | |||||
subdir_content, | |||||
path=subdir_path, | |||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
Show All 35 Lines | _origin_directory_view_test_helper( | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
timestamp=visit_unix_ts, | |||||
) | |||||
_origin_directory_view_test_helper( | |||||
client, | |||||
archive_data, | |||||
origin, | |||||
visit, | |||||
branches, | |||||
releases, | |||||
root_dir_sha1, | |||||
subdir_content, | |||||
path=subdir_path, | |||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
▲ Show 20 Lines • Show All 479 Lines • ▼ Show 20 Lines | ): | ||||
path = content_path.replace(filename, "")[:-1] | path = content_path.replace(filename, "")[:-1] | ||||
path_info = gen_path_info(path) | path_info = gen_path_info(path) | ||||
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_iso8601_date_to_utc(timestamp).isoformat(), "%Y-%m-%dT%H:%M:%SZ" | ||||
) | ) | ||||
root_dir_url = reverse("browse-origin-directory", query_params=query_params) | root_dir_url = reverse("browse-origin-directory", 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])) | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | ): | ||||
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_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_timestamp(timestamp).isoformat(), "%Y-%m-%dT%H:%M:%SZ" | parse_iso8601_date_to_utc(timestamp).isoformat(), "%Y-%m-%dT%H:%M:%SZ" | ||||
) | ) | ||||
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: | ||||
▲ Show 20 Lines • Show All 233 Lines • Show Last 20 Lines |