Skip to content
Snippets Groups Projects
Commit fca36585 authored by David Douard's avatar David Douard
Browse files

Fix MetadataAuthority.from_dict()

was modifying the dict given as argument.
parent 2185f930
No related branches found
No related tags found
No related merge requests found
......@@ -848,7 +848,10 @@ class MetadataAuthority(BaseModel):
@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:
......
......@@ -45,6 +45,7 @@ from swh.model.model import (
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 @@ def test_todict_inverse_fromdict(objtype_and_obj):
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)
......
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