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 @@ -45,7 +45,7 @@ return builds( TimestampWithTimezone, timestamp=timestamps(), - offset=integers(-2**16, 2**16-1)) + offset=integers(min_value=-14*60, max_value=14*60)) def origins(): @@ -77,8 +77,8 @@ id=sha1_git(), date=timestamps_with_timezone(), committer_date=timestamps_with_timezone(), - parents=lists(binary()), - directory=binary(), + parents=lists(sha1_git()), + directory=sha1_git(), metadata=one_of(none(), dictionaries(binary(), binary()))) diff --git a/swh/model/model.py b/swh/model/model.py --- a/swh/model/model.py +++ b/swh/model/model.py @@ -48,6 +48,13 @@ def to_dict(self): return attr.asdict(self) + @offset.validator + def check_offset(self, attribute, value): + if not (-2**15 <= value < 2**15): + # max 14 hours offset in theory, but you never know what + # you'll find in the wild... + raise ValueError('offset too big: %d minutes' % value) + @attr.s class Origin: @@ -134,6 +141,14 @@ return rel +class RevisionType(Enum): + GIT = 'git' + TAR = 'tar' + DSC = 'dsc' + SUBVERSION = 'svn' + MERCURIAL = 'hg' + + @attr.s class Revision: id = attr.ib(type=Sha1Git) @@ -143,7 +158,7 @@ date = attr.ib(type=TimestampWithTimezone) committer_date = attr.ib(type=TimestampWithTimezone) parents = attr.ib(type=List[Sha1Git]) - type = attr.ib(type=str) + type = attr.ib(type=RevisionType) directory = attr.ib(type=Sha1Git) metadata = attr.ib(type=Optional[dict]) synthetic = attr.ib(type=bool) @@ -152,6 +167,7 @@ rev = attr.asdict(self) rev['date'] = self.date.to_dict() rev['committer_date'] = self.committer_date.to_dict() + rev['type'] = rev['type'].value return rev