Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9311937
D2607.id9324.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
D2607.id9324.diff
View Options
diff --git a/swh/model/model.py b/swh/model/model.py
--- a/swh/model/model.py
+++ b/swh/model/model.py
@@ -296,8 +296,8 @@
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 @@
@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)
diff --git a/swh/model/tests/test_model.py b/swh/model/tests/test_model.py
--- a/swh/model/tests/test_model.py
+++ b/swh/model/tests/test_model.py
@@ -66,49 +66,49 @@
dir_dict = dict(directory_example)
del dir_dict['id']
- dir_model = Directory(**dir_dict)
- assert dir_model.id
- assert dir_model.id == hash_to_bytes(directory_identifier(dir_dict))
-
- dir_model = Directory.from_dict(dir_dict)
- assert dir_model.id
- assert dir_model.id == hash_to_bytes(directory_identifier(dir_dict))
+ dir_id = hash_to_bytes(directory_identifier(dir_dict))
+ for dir_model in [Directory(**dir_dict), Directory.from_dict(dir_dict)]:
+ assert dir_model.id == dir_id
def test_revision_model_id_computation():
rev_dict = dict(revision_example)
del rev_dict['id']
- rev_model = Revision(**rev_dict)
- assert rev_model.id
- assert rev_model.id == hash_to_bytes(revision_identifier(rev_dict))
+ rev_id = hash_to_bytes(revision_identifier(rev_dict))
+ for rev_model in [Revision(**rev_dict), Revision.from_dict(rev_dict)]:
+ assert rev_model.id == rev_id
+
+
+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_model = Revision.from_dict(rev_dict)
- assert rev_model.id
- assert rev_model.id == hash_to_bytes(revision_identifier(rev_dict))
+ 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']
- rel_model = Release(**rel_dict)
- assert rel_model.id
- assert rel_model.id == hash_to_bytes(release_identifier(rel_dict))
-
- rel_model = Release.from_dict(rel_dict)
- assert rel_model.id
- assert rel_model.id == hash_to_bytes(release_identifier(rel_dict))
+ rel_id = hash_to_bytes(release_identifier(rel_dict))
+ for rel_model in [Release(**rel_dict), Release.from_dict(rel_dict)]:
+ assert rel_model.id == hash_to_bytes(rel_id)
def test_snapshot_model_id_computation():
snp_dict = dict(snapshot_example)
del snp_dict['id']
- snp_model = Snapshot(**snp_dict)
- assert snp_model.id
- assert snp_model.id == hash_to_bytes(snapshot_identifier(snp_dict))
-
- snp_model = Snapshot.from_dict(snp_dict)
- assert snp_model.id
- assert snp_model.id == hash_to_bytes(snapshot_identifier(snp_dict))
+ snp_id = hash_to_bytes(snapshot_identifier(snp_dict))
+ for snp_model in [Snapshot(**snp_dict), Snapshot.from_dict(snp_dict)]:
+ assert snp_model.id == snp_id
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jul 2, 10:37 AM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3222600
Attached To
D2607: model: Update revision date types to be optional
Event Timeline
Log In to Comment