Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/test_snapshot_context.py
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | ): | ||||
visit_info = get_origin_visit( | visit_info = get_origin_visit( | ||||
{"url": kwargs["origin_url"]}, visit_ts=visit_ts, visit_id=visit_id | {"url": kwargs["origin_url"]}, visit_ts=visit_ts, visit_id=visit_id | ||||
) | ) | ||||
snapshot = visit_info["snapshot"] | snapshot = visit_info["snapshot"] | ||||
snapshot_context = get_snapshot_context(**kwargs, browse_context=browse_context) | snapshot_context = get_snapshot_context(**kwargs, browse_context=browse_context) | ||||
url_args = dict(kwargs) | |||||
url_args.pop("path", None) | |||||
url_args.pop("timestamp", None) | |||||
url_args.pop("visit_id", None) | |||||
query_params = dict(kwargs) | query_params = dict(kwargs) | ||||
query_params.pop("origin_url") | |||||
branches, releases = get_snapshot_content(snapshot) | branches, releases = get_snapshot_content(snapshot) | ||||
releases = list(reversed(releases)) | releases = list(reversed(releases)) | ||||
revision_id = None | revision_id = None | ||||
root_directory = None | root_directory = None | ||||
for branch in branches: | for branch in branches: | ||||
if branch["name"] == "HEAD": | if branch["name"] == "HEAD": | ||||
revision_id = branch["revision"] | revision_id = branch["revision"] | ||||
root_directory = branch["directory"] | root_directory = branch["directory"] | ||||
branch["url"] = reverse( | branch["url"] = reverse( | ||||
f"browse-origin-{browse_context}", | f"browse-origin-{browse_context}", | ||||
url_args=url_args, | |||||
query_params={"branch": branch["name"], **query_params}, | query_params={"branch": branch["name"], **query_params}, | ||||
) | ) | ||||
for release in releases: | for release in releases: | ||||
release["url"] = reverse( | release["url"] = reverse( | ||||
f"browse-origin-{browse_context}", | f"browse-origin-{browse_context}", | ||||
url_args=url_args, | |||||
query_params={"release": release["name"], **query_params}, | query_params={"release": release["name"], **query_params}, | ||||
) | ) | ||||
query_params.pop("path", None) | query_params.pop("path", None) | ||||
branches_url = reverse( | branches_url = reverse("browse-origin-branches", query_params=query_params) | ||||
"browse-origin-branches", url_args=url_args, query_params=query_params | releases_url = reverse("browse-origin-releases", query_params=query_params) | ||||
) | |||||
releases_url = reverse( | |||||
"browse-origin-releases", url_args=url_args, query_params=query_params | |||||
) | |||||
origin_visits_url = reverse( | origin_visits_url = reverse( | ||||
"browse-origin-visits", url_args={"origin_url": kwargs["origin_url"]} | "browse-origin-visits", query_params={"origin_url": kwargs["origin_url"]} | ||||
) | ) | ||||
is_empty = not branches and not releases | is_empty = not branches and not releases | ||||
snapshot_swhid = get_swh_persistent_id("snapshot", snapshot) | snapshot_swhid = get_swh_persistent_id("snapshot", snapshot) | ||||
snapshot_sizes = {"revision": len(branches), "release": len(releases)} | snapshot_sizes = {"revision": len(branches), "release": len(releases)} | ||||
visit_info["url"] = reverse( | visit_info["url"] = reverse( | ||||
"browse-origin-directory", url_args=url_args, query_params=query_params | "browse-origin-directory", query_params=query_params | ||||
) | ) | ||||
visit_info["formatted_date"] = format_utc_iso_date(visit_info["date"]) | visit_info["formatted_date"] = format_utc_iso_date(visit_info["date"]) | ||||
if "path" in kwargs: | if "path" in kwargs: | ||||
query_params["path"] = kwargs["path"] | query_params["path"] = kwargs["path"] | ||||
expected = SnapshotContext( | expected = SnapshotContext( | ||||
branch="HEAD", | branch="HEAD", | ||||
branches=branches, | branches=branches, | ||||
branches_url=branches_url, | branches_url=branches_url, | ||||
is_empty=is_empty, | is_empty=is_empty, | ||||
origin_info={"url": origin["url"]}, | origin_info={"url": origin["url"]}, | ||||
origin_visits_url=origin_visits_url, | origin_visits_url=origin_visits_url, | ||||
release=None, | release=None, | ||||
release_id=None, | release_id=None, | ||||
query_params=query_params, | query_params=query_params, | ||||
releases=releases, | releases=releases, | ||||
releases_url=releases_url, | releases_url=releases_url, | ||||
revision_id=revision_id, | revision_id=revision_id, | ||||
root_directory=root_directory, | root_directory=root_directory, | ||||
snapshot_id=snapshot, | snapshot_id=snapshot, | ||||
snapshot_sizes=snapshot_sizes, | snapshot_sizes=snapshot_sizes, | ||||
snapshot_swhid=snapshot_swhid, | snapshot_swhid=snapshot_swhid, | ||||
url_args=url_args, | url_args={}, | ||||
visit_info=visit_info, | visit_info=visit_info, | ||||
) | ) | ||||
assert snapshot_context == expected | assert snapshot_context == expected | ||||
_check_branch_release_revision_parameters( | _check_branch_release_revision_parameters( | ||||
archive_data, expected, browse_context, kwargs, branches, releases | archive_data, expected, browse_context, kwargs, branches, releases | ||||
) | ) | ||||
def _check_branch_release_revision_parameters( | def _check_branch_release_revision_parameters( | ||||
archive_data, base_expected_context, browse_context, kwargs, branches, releases, | archive_data, base_expected_context, browse_context, kwargs, branches, releases, | ||||
): | ): | ||||
branch = random.choice(branches) | branch = random.choice(branches) | ||||
snapshot_context = get_snapshot_context( | snapshot_context = get_snapshot_context( | ||||
**kwargs, browse_context=browse_context, branch_name=branch["name"] | **kwargs, browse_context=browse_context, branch_name=branch["name"] | ||||
) | ) | ||||
url_args = dict(kwargs) | url_args = dict(kwargs) | ||||
url_args.pop("path", None) | url_args.pop("path", None) | ||||
url_args.pop("timestamp", None) | url_args.pop("timestamp", None) | ||||
url_args.pop("visit_id", None) | url_args.pop("visit_id", None) | ||||
url_args.pop("origin_url", None) | |||||
query_params = dict(kwargs) | query_params = dict(kwargs) | ||||
query_params.pop("origin_url", None) | |||||
query_params.pop("snapshot_id", None) | query_params.pop("snapshot_id", None) | ||||
expected_branch = dict(base_expected_context) | expected_branch = dict(base_expected_context) | ||||
expected_branch["branch"] = branch["name"] | expected_branch["branch"] = branch["name"] | ||||
expected_branch["revision_id"] = branch["revision"] | expected_branch["revision_id"] = branch["revision"] | ||||
expected_branch["root_directory"] = branch["directory"] | expected_branch["root_directory"] = branch["directory"] | ||||
expected_branch["query_params"] = {"branch": branch["name"], **query_params} | expected_branch["query_params"] = {"branch": branch["name"], **query_params} | ||||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |