Page MenuHomeSoftware Heritage

D2159.diff
No OneTemporary

D2159.diff

diff --git a/swh/model/model.py b/swh/model/model.py
--- a/swh/model/model.py
+++ b/swh/model/model.py
@@ -97,6 +97,11 @@
url = attr.ib(type=str)
type = attr.ib(type=Optional[str], default=None)
+ def to_dict(self):
+ r = super().to_dict()
+ r.pop('type', None)
+ return r
+
@attr.s
class OriginVisit(BaseModel):
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
@@ -8,12 +8,16 @@
from hypothesis import given
from swh.model.model import Content
-from swh.model.hypothesis_strategies import objects
+from swh.model.hypothesis_strategies import objects, origins
@given(objects())
def test_todict_inverse_fromdict(objtype_and_obj):
(obj_type, obj) = objtype_and_obj
+
+ if obj_type == 'origin':
+ return
+
obj_as_dict = obj.to_dict()
obj_as_dict_copy = copy.deepcopy(obj_as_dict)
@@ -27,6 +31,14 @@
assert obj_as_dict == type(obj).from_dict(obj_as_dict).to_dict()
+@given(origins())
+def test_todict_origins(origin):
+ obj = origin.to_dict()
+
+ assert 'type' not in obj
+ assert type(origin)(url=origin.url) == type(origin).from_dict(obj)
+
+
def test_content_get_hash():
hashes = dict(
sha1=b'foo', sha1_git=b'bar', sha256=b'baz', blake2s256=b'qux')

File Metadata

Mime Type
text/plain
Expires
Thu, Jul 3, 12:55 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3221794

Event Timeline