diff --git a/swh/model/hypothesis_strategies.py b/swh/model/hypothesis_strategies.py --- a/swh/model/hypothesis_strategies.py +++ b/swh/model/hypothesis_strategies.py @@ -26,6 +26,10 @@ blacklist_characters=['\u0000']) # postgresql does not like these +def optional(strategy): + return one_of(none(), strategy) + + def pgsql_text(): return text(alphabet=pgsql_alphabet) @@ -81,7 +85,8 @@ visit=integers(0, 1000), origin=urls(), status=sampled_from(['ongoing', 'full', 'partial']), - type=pgsql_text()) + type=pgsql_text(), + snapshot=optional(sha1_git())) @composite @@ -148,9 +153,6 @@ @composite def skipped_contents(draw): - def optional(strategy): - return one_of(none(), strategy) - return draw(builds( SkippedContent, length=integers(min_value=-1, max_value=2**63-1), diff --git a/swh/model/model.py b/swh/model/model.py --- a/swh/model/model.py +++ b/swh/model/model.py @@ -149,7 +149,7 @@ type=str, validator=attr.validators.in_(['ongoing', 'full', 'partial'])) type = attr.ib(type=str) - snapshot = attr.ib(type=Sha1Git) + snapshot = attr.ib(type=Optional[Sha1Git]) metadata = attr.ib(type=Optional[Dict[str, object]], default=None)