Skip to content
Snippets Groups Projects
Commit 7a9fc396 authored by Nicolas Dandrimont's avatar Nicolas Dandrimont
Browse files

model: Don't export origin['type']

parent c103a6f9
No related branches found
No related tags found
No related merge requests found
......@@ -97,6 +97,11 @@ class Origin(BaseModel):
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):
......
......@@ -8,12 +8,16 @@ import copy
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 @@ def test_todict_inverse_fromdict(objtype_and_obj):
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')
......
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