Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9342123
D5215.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D5215.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
@@ -848,7 +848,10 @@
@classmethod
def from_dict(cls, d):
- d["type"] = MetadataAuthorityType(d["type"])
+ d = {
+ **d,
+ "type": MetadataAuthorityType(d["type"]),
+ }
return super().from_dict(d)
def unique_key(self) -> KeyType:
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
@@ -45,6 +45,7 @@
Timestamp,
TimestampWithTimezone,
)
+from swh.model.tests.swh_model_data import TEST_OBJECTS
from swh.model.tests.test_identifiers import (
content_example,
directory_example,
@@ -78,6 +79,17 @@
assert obj_as_dict == type(obj).from_dict(obj_as_dict).to_dict()
+@pytest.mark.parametrize("object_type, objects", TEST_OBJECTS.items())
+def test_swh_model_todict_fromdict(object_type, objects):
+ """checks model objects in swh_model_data are in correct shape"""
+ assert objects
+ for obj in objects:
+ # Check the composition of from_dict and to_dict is the identity
+ obj_as_dict = obj.to_dict()
+ assert obj == type(obj).from_dict(obj_as_dict)
+ assert obj_as_dict == type(obj).from_dict(obj_as_dict).to_dict()
+
+
def test_unique_key():
url = "http://example.org/"
date = datetime.datetime.now(tz=datetime.timezone.utc)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 3, 12:30 PM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217316
Attached To
D5215: Fix MetadataAuthority.from_dict()
Event Timeline
Log In to Comment