diff --git a/swh/web/common/archive.py b/swh/web/common/archive.py --- a/swh/web/common/archive.py +++ b/swh/web/common/archive.py @@ -866,7 +866,7 @@ c = lookup_content(q) content_sha1_bytes = hashutil.hash_to_bytes(c["checksums"]["sha1"]) content_data = storage.content_get_data(content_sha1_bytes) - if not content_data: + if content_data is None: algo, hash_ = query.parse_hash(q) raise NotFoundExc( f"Bytes of content with {algo} checksum equals " diff --git a/swh/web/tests/common/test_archive.py b/swh/web/tests/common/test_archive.py --- a/swh/web/tests/common/test_archive.py +++ b/swh/web/tests/common/test_archive.py @@ -26,6 +26,7 @@ contents, contents_with_ctags, directory, + empty_content, empty_directory, invalid_sha1, new_origin, @@ -627,6 +628,12 @@ assert actual_content == expected_content +@given(empty_content()) +def test_lookup_empty_content_raw(archive_data, empty_content): + content_raw = archive.lookup_content_raw(f"sha1_git:{empty_content['sha1_git']}") + assert content_raw["data"] == b"" + + def test_lookup_content_not_found(): unknown_content_ = random_content() diff --git a/swh/web/tests/data.py b/swh/web/tests/data.py --- a/swh/web/tests/data.py +++ b/swh/web/tests/data.py @@ -287,6 +287,9 @@ # Add the empty directory to the test archive storage.directory_add([Directory(entries=())]) + # Add empty content to the test archive + storage.content_add([Content.from_data(data=b"")]) + # Return tests data return { "search": search, diff --git a/swh/web/tests/strategies.py b/swh/web/tests/strategies.py --- a/swh/web/tests/strategies.py +++ b/swh/web/tests/strategies.py @@ -20,11 +20,17 @@ text, ) -from swh.model.hashutil import hash_to_bytes, hash_to_hex +from swh.model.hashutil import DEFAULT_ALGORITHMS, hash_to_bytes, hash_to_hex from swh.model.hypothesis_strategies import origins as new_origin_strategy from swh.model.hypothesis_strategies import snapshots as new_snapshot from swh.model.identifiers import directory_identifier -from swh.model.model import Person, Revision, RevisionType, TimestampWithTimezone +from swh.model.model import ( + Content, + Person, + Revision, + RevisionType, + TimestampWithTimezone, +) from swh.storage.algos.revisions_walker import get_revisions_walker from swh.storage.algos.snapshot import snapshot_get_latest from swh.web.common.utils import browsers_supported_image_mimes @@ -93,6 +99,17 @@ return lists(content(), min_size=2, max_size=8) +def empty_content(): + """ + Hypothesis strategy returning the empty content ingested + into the test archive. + """ + empty_content = Content.from_data(data=b"").to_dict() + for algo in DEFAULT_ALGORITHMS: + empty_content[algo] = hash_to_hex(empty_content[algo]) + return just(empty_content) + + def content_text(): """ Hypothesis strategy returning random textual contents ingested