Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/strategies.py
Show All 14 Lines | from hypothesis.strategies import ( | ||||
composite, | composite, | ||||
datetimes, | datetimes, | ||||
just, | just, | ||||
lists, | lists, | ||||
sampled_from, | sampled_from, | ||||
text, | 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 origins as new_origin_strategy | ||||
from swh.model.hypothesis_strategies import snapshots as new_snapshot | from swh.model.hypothesis_strategies import snapshots as new_snapshot | ||||
from swh.model.identifiers import directory_identifier | 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.revisions_walker import get_revisions_walker | ||||
from swh.storage.algos.snapshot import snapshot_get_latest | from swh.storage.algos.snapshot import snapshot_get_latest | ||||
from swh.web.common.utils import browsers_supported_image_mimes | from swh.web.common.utils import browsers_supported_image_mimes | ||||
from swh.web.tests.data import get_tests_data | from swh.web.tests.data import get_tests_data | ||||
# Module dedicated to the generation of input data for tests through | # Module dedicated to the generation of input data for tests through | ||||
# the use of hypothesis. | # the use of hypothesis. | ||||
# Some of these data are sampled from a test archive created and populated | # Some of these data are sampled from a test archive created and populated | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
def contents(): | def contents(): | ||||
""" | """ | ||||
Hypothesis strategy returning random contents ingested | Hypothesis strategy returning random contents ingested | ||||
into the test archive. | into the test archive. | ||||
""" | """ | ||||
return lists(content(), min_size=2, max_size=8) | 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(): | def content_text(): | ||||
""" | """ | ||||
Hypothesis strategy returning random textual contents ingested | Hypothesis strategy returning random textual contents ingested | ||||
into the test archive. | into the test archive. | ||||
""" | """ | ||||
return content().filter(lambda c: c["mimetype"].startswith("text/")) | return content().filter(lambda c: c["mimetype"].startswith("text/")) | ||||
▲ Show 20 Lines • Show All 497 Lines • Show Last 20 Lines |