Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/common/test_identifiers.py
Show First 20 Lines • Show All 493 Lines • ▼ Show 20 Lines | ): | ||||
_check_resolved_swhid_browse_url( | _check_resolved_swhid_browse_url( | ||||
CONTENT, | CONTENT, | ||||
directory_file["target"], | directory_file["target"], | ||||
snapshot_context, | snapshot_context, | ||||
path=f"/{directory_file['name']}", | path=f"/{directory_file['name']}", | ||||
) | ) | ||||
_check_resolved_swhid_browse_url( | |||||
CONTENT, | |||||
directory_file["target"], | |||||
snapshot_context, | |||||
path=f"/{directory_file['name']}", | |||||
lines="10", | |||||
) | |||||
_check_resolved_swhid_browse_url( | |||||
CONTENT, | |||||
directory_file["target"], | |||||
snapshot_context, | |||||
path=f"/{directory_file['name']}", | |||||
lines="10-20", | |||||
) | |||||
def _check_resolved_swhid_browse_url( | def _check_resolved_swhid_browse_url( | ||||
object_type, object_id, snapshot_context, path=None | object_type, object_id, snapshot_context, path=None, lines=None | ||||
): | ): | ||||
snapshot_id = snapshot_context["snapshot_id"] | snapshot_id = snapshot_context["snapshot_id"] | ||||
origin_url = None | origin_url = None | ||||
if snapshot_context["origin_info"]: | if snapshot_context["origin_info"]: | ||||
origin_url = snapshot_context["origin_info"]["url"] | origin_url = snapshot_context["origin_info"]["url"] | ||||
obj_context = {} | obj_context = {} | ||||
query_params = {} | query_params = {} | ||||
Show All 39 Lines | if path: | ||||
if object_type == CONTENT: | if object_type == CONTENT: | ||||
query_params["path"] = path[1:] | query_params["path"] = path[1:] | ||||
else: | else: | ||||
query_params["path"] = path[1:-1] | query_params["path"] = path[1:-1] | ||||
if object_type == DIRECTORY: | if object_type == DIRECTORY: | ||||
object_id = snapshot_context["root_directory"] | object_id = snapshot_context["root_directory"] | ||||
if lines: | |||||
obj_context["lines"] = lines | |||||
obj_swhid = get_swh_persistent_id(object_type, object_id, metadata=obj_context) | obj_swhid = get_swh_persistent_id(object_type, object_id, metadata=obj_context) | ||||
obj_swhid_resolved = resolve_swh_persistent_id(obj_swhid) | obj_swhid_resolved = resolve_swh_persistent_id(obj_swhid) | ||||
url_args = {"sha1_git": object_id} | url_args = {"sha1_git": object_id} | ||||
if object_type == CONTENT: | if object_type == CONTENT: | ||||
url_args = {"query_string": f"sha1_git:{object_id}"} | url_args = {"query_string": f"sha1_git:{object_id}"} | ||||
elif object_type == SNAPSHOT: | elif object_type == SNAPSHOT: | ||||
url_args = {"snapshot_id": object_id} | url_args = {"snapshot_id": object_id} | ||||
expected_url = reverse( | expected_url = reverse( | ||||
f"browse-{object_type}", url_args=url_args, query_params=query_params, | f"browse-{object_type}", url_args=url_args, query_params=query_params, | ||||
) | ) | ||||
if lines: | |||||
lines_number = lines.split("-") | |||||
expected_url += f"#L{lines_number[0]}" | |||||
if len(lines_number) > 1: | |||||
expected_url += f"-L{lines_number[1]}" | |||||
assert obj_swhid_resolved["browse_url"] == expected_url | assert obj_swhid_resolved["browse_url"] == expected_url |