Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/strategies.py
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | def unknown_directory(): | ||||
return sha1().filter( | return sha1().filter( | ||||
lambda s: len( | lambda s: len( | ||||
list(get_tests_data()["storage"].directory_missing([hash_to_bytes(s)])) | list(get_tests_data()["storage"].directory_missing([hash_to_bytes(s)])) | ||||
) | ) | ||||
> 0 | > 0 | ||||
) | ) | ||||
def origin(): | |||||
""" | |||||
Hypothesis strategy returning a random origin ingested | |||||
into the test archive. | |||||
""" | |||||
return _known_swh_object("origins") | |||||
def origin_with_multiple_visits(): | |||||
""" | |||||
Hypothesis strategy returning a random origin ingested | |||||
into the test archive. | |||||
""" | |||||
ret = [] | |||||
tests_data = get_tests_data() | |||||
storage = tests_data["storage"] | |||||
for origin in tests_data["origins"]: | |||||
visit_page = storage.origin_visit_get(origin["url"]) | |||||
if len(visit_page.results) > 1: | |||||
ret.append(origin) | |||||
return sampled_from(ret) | |||||
def origin_with_releases(): | |||||
""" | |||||
Hypothesis strategy returning a random origin ingested | |||||
into the test archive. | |||||
""" | |||||
ret = [] | |||||
tests_data = get_tests_data() | |||||
for origin in tests_data["origins"]: | |||||
snapshot = snapshot_get_latest(tests_data["storage"], origin["url"]) | |||||
if any([b.target_type.value == "release" for b in snapshot.branches.values()]): | |||||
ret.append(origin) | |||||
return sampled_from(ret) | |||||
def origin_with_pull_request_branches(): | |||||
""" | |||||
Hypothesis strategy returning a random origin with pull request branches | |||||
ingested into the test archive. | |||||
""" | |||||
ret = [] | |||||
tests_data = get_tests_data() | |||||
storage = tests_data["storage"] | |||||
origins = storage.origin_list(limit=1000) | |||||
for origin in origins.results: | |||||
snapshot = snapshot_get_latest(storage, origin.url) | |||||
if any([b"refs/pull/" in b for b in snapshot.branches]): | |||||
ret.append(origin) | |||||
return sampled_from(ret) | |||||
def new_origin(): | def new_origin(): | ||||
""" | """ | ||||
Hypothesis strategy returning a random origin not ingested | Hypothesis strategy returning a random origin not ingested | ||||
into the test archive. | into the test archive. | ||||
""" | """ | ||||
return new_origin_strategy() | return new_origin_strategy() | ||||
▲ Show 20 Lines • Show All 308 Lines • Show Last 20 Lines |