Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_directory.py
Show First 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | ): | ||||
visit = random.choice(visits) | visit = random.choice(visits) | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
snapshot_sizes = archive_data.snapshot_count_branches(visit["snapshot"]) | snapshot_sizes = archive_data.snapshot_count_branches(visit["snapshot"]) | ||||
branches, releases, _ = process_snapshot_branches(snapshot) | branches, releases, _ = process_snapshot_branches(snapshot) | ||||
branch_info = next( | branch_info = next( | ||||
branch for branch in branches if branch["name"] == "refs/heads/master" | branch for branch in branches if branch["name"] == "refs/heads/master" | ||||
) | ) | ||||
directory = archive_data.revision_get(branch_info["revision"])["directory"] | directory = archive_data.revision_get(branch_info["target"])["directory"] | ||||
directory_content = archive_data.directory_ls(directory) | directory_content = archive_data.directory_ls(directory) | ||||
directory_subdir = random.choice( | directory_subdir = random.choice( | ||||
[e for e in directory_content if e["type"] == "dir"] | [e for e in directory_content if e["type"] == "dir"] | ||||
) | ) | ||||
url = reverse( | url = reverse( | ||||
"browse-directory", | "browse-directory", | ||||
url_args={"sha1_git": directory}, | url_args={"sha1_git": directory}, | ||||
Show All 16 Lines | ): | ||||
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( | ||||
ObjectType.DIRECTORY, | ObjectType.DIRECTORY, | ||||
directory_subdir["target"], | directory_subdir["target"], | ||||
metadata={ | metadata={ | ||||
"origin": origin_url, | "origin": origin_url, | ||||
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]), | "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]), | ||||
"anchor": gen_swhid(ObjectType.REVISION, branch_info["revision"]), | "anchor": gen_swhid(ObjectType.REVISION, branch_info["target"]), | ||||
"path": "/", | "path": "/", | ||||
}, | }, | ||||
) | ) | ||||
assert_contains(resp, dir_swhid) | assert_contains(resp, dir_swhid) | ||||
rev_swhid = gen_swhid( | rev_swhid = gen_swhid( | ||||
ObjectType.REVISION, | ObjectType.REVISION, | ||||
branch_info["revision"], | branch_info["target"], | ||||
metadata={ | metadata={ | ||||
"origin": origin_url, | "origin": origin_url, | ||||
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]), | "visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]), | ||||
}, | }, | ||||
) | ) | ||||
assert_contains(resp, rev_swhid) | assert_contains(resp, rev_swhid) | ||||
snp_swhid = gen_swhid( | snp_swhid = gen_swhid( | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | ): | ||||
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"]) | ||||
branches, releases, _ = process_snapshot_branches(snapshot) | branches, releases, _ = process_snapshot_branches(snapshot) | ||||
branch_info = next( | branch_info = next( | ||||
branch for branch in branches if branch["name"] == "refs/heads/master" | branch for branch in branches if branch["name"] == "refs/heads/master" | ||||
) | ) | ||||
directory = archive_data.revision_get(branch_info["revision"])["directory"] | directory = archive_data.revision_get(branch_info["target"])["directory"] | ||||
directory_content = archive_data.directory_ls(directory) | directory_content = archive_data.directory_ls(directory) | ||||
directory_subdir = random.choice( | directory_subdir = random.choice( | ||||
[e for e in directory_content if e["type"] == "dir"] | [e for e in directory_content if e["type"] == "dir"] | ||||
) | ) | ||||
url = reverse( | url = reverse( | ||||
"browse-directory", | "browse-directory", | ||||
url_args={"sha1_git": directory}, | url_args={"sha1_git": directory}, | ||||
query_params={ | query_params={ | ||||
"origin_url": origin_url, | "origin_url": origin_url, | ||||
"snapshot": snapshot["id"], | "snapshot": snapshot["id"], | ||||
"revision": branch_info["revision"], | "revision": branch_info["target"], | ||||
"path": directory_subdir["name"], | "path": directory_subdir["name"], | ||||
}, | }, | ||||
) | ) | ||||
resp = check_html_get_response( | resp = check_html_get_response( | ||||
client, url, status_code=200, template_used="browse-directory.html" | client, url, status_code=200, template_used="browse-directory.html" | ||||
) | ) | ||||
assert_contains(resp, f"Revision: <strong>{branch_info['revision']}</strong>") | assert_contains(resp, f"Revision: <strong>{branch_info['target']}</strong>") | ||||
def _check_origin_snapshot_related_html( | def _check_origin_snapshot_related_html( | ||||
resp, origin, snapshot, snapshot_sizes, branches, releases | resp, origin, snapshot, snapshot_sizes, branches, releases | ||||
): | ): | ||||
browse_origin_url = reverse( | browse_origin_url = reverse( | ||||
"browse-origin", query_params={"origin_url": origin["url"]} | "browse-origin", query_params={"origin_url": origin["url"]} | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 176 Lines • Show Last 20 Lines |