diff --git a/swh/web/tests/common/test_identifiers.py b/swh/web/tests/common/test_identifiers.py --- a/swh/web/tests/common/test_identifiers.py +++ b/swh/web/tests/common/test_identifiers.py @@ -156,25 +156,30 @@ dir_subdir_content = archive_data.directory_ls(dir_subdir["target"]) dir_subdir_files = [e for e in dir_subdir_content if e["type"] == "file"] - dir_subdir_file = random.choice(dir_subdir_files) + + swh_objects_info = [ + SWHObjectInfo(object_type=DIRECTORY, object_id=dir_subdir["target"]) + ] extra_context = { "root_directory": directory, "path": dir_subdir_path, - "filename": dir_subdir_file["name"], } - swhids = get_swhids_info( - [ - SWHObjectInfo(object_type=DIRECTORY, object_id=dir_subdir["target"]), + + if dir_subdir_files: + dir_subdir_file = random.choice(dir_subdir_files) + extra_context["filename"] = dir_subdir_file["name"] + swh_objects_info.append( SWHObjectInfo( object_type=CONTENT, object_id=dir_subdir_file["checksums"]["sha1_git"] - ), - ], - snapshot_context=None, - extra_context=extra_context, + ) + ) + + swhids = get_swhids_info( + swh_objects_info, snapshot_context=None, extra_context=extra_context, ) + swhid_dir_parsed = get_persistent_identifier(swhids[0]["swhid_with_context"]) - swhid_cnt_parsed = get_persistent_identifier(swhids[1]["swhid_with_context"]) anchor = get_swh_persistent_id(DIRECTORY, directory) @@ -183,10 +188,13 @@ "path": dir_subdir_path, } - assert swhid_cnt_parsed.metadata == { - "anchor": anchor, - "path": f'{dir_subdir_path}{dir_subdir_file["name"]}', - } + if dir_subdir_files: + swhid_cnt_parsed = get_persistent_identifier(swhids[1]["swhid_with_context"]) + + assert swhid_cnt_parsed.metadata == { + "anchor": anchor, + "path": f'{dir_subdir_path}{dir_subdir_file["name"]}', + } @given(revision())