Skip to content
Snippets Groups Projects
Verified Commit b54adf79 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

model: Update revision date types to be optional

Related to P589
parent 57a0e089
No related branches found
No related tags found
No related merge requests found
......@@ -296,8 +296,8 @@ class Revision(BaseModel, HashableObject):
message = attr.ib(type=bytes)
author = attr.ib(type=Person)
committer = attr.ib(type=Person)
date = attr.ib(type=TimestampWithTimezone)
committer_date = attr.ib(type=TimestampWithTimezone)
date = attr.ib(type=Optional[TimestampWithTimezone])
committer_date = attr.ib(type=Optional[TimestampWithTimezone])
type = attr.ib(type=RevisionType)
directory = attr.ib(type=Sha1Git)
synthetic = attr.ib(type=bool)
......@@ -314,12 +314,20 @@ class Revision(BaseModel, HashableObject):
@classmethod
def from_dict(cls, d):
d = d.copy()
date = d.pop('date')
if date:
date = TimestampWithTimezone.from_dict(date)
committer_date = d.pop('committer_date')
if committer_date:
committer_date = TimestampWithTimezone.from_dict(
committer_date)
return cls(
author=Person.from_dict(d.pop('author')),
committer=Person.from_dict(d.pop('committer')),
date=TimestampWithTimezone.from_dict(d.pop('date')),
committer_date=TimestampWithTimezone.from_dict(
d.pop('committer_date')),
date=date,
committer_date=committer_date,
type=RevisionType(d.pop('type')),
**d)
......
......@@ -88,6 +88,22 @@ def test_revision_model_id_computation():
assert rev_model.id == hash_to_bytes(revision_identifier(rev_dict))
def test_revision_model_id_computation_with_no_date():
"""We can have revision with date to None
"""
rev_dict = dict(revision_example)
rev_dict['date'] = None
rev_dict['committer_date'] = None
del rev_dict['id']
rev_id = hash_to_bytes(revision_identifier(rev_dict))
for rev_model in [Revision(**rev_dict), Revision.from_dict(rev_dict)]:
assert rev_model.date is None
assert rev_model.committer_date is None
assert rev_model.id == rev_id
def test_release_model_id_computation():
rel_dict = dict(release_example)
del rel_dict['id']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment