From 0b9c5be2f7d9635154a4d8fc2e8f431825d96259 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz <vlorentz@softwareheritage.org> Date: Wed, 30 Oct 2019 14:36:25 +0100 Subject: [PATCH] Make OriginVisit.origin a string instead of a dict. --- swh/model/hypothesis_strategies.py | 2 +- swh/model/model.py | 3 +-- swh/model/tests/test_model.py | 6 +----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/swh/model/hypothesis_strategies.py b/swh/model/hypothesis_strategies.py index ca568ee7..e9acfa1e 100644 --- a/swh/model/hypothesis_strategies.py +++ b/swh/model/hypothesis_strategies.py @@ -79,7 +79,7 @@ def origin_visits(): return builds( OriginVisit, visit=integers(0, 1000), - origin=origins(), + origin=urls(), status=sampled_from(['ongoing', 'full', 'partial']), type=pgsql_text()) diff --git a/swh/model/model.py b/swh/model/model.py index baf4f541..8c31f6d6 100644 --- a/swh/model/model.py +++ b/swh/model/model.py @@ -121,7 +121,7 @@ class Origin(BaseModel): class OriginVisit(BaseModel): """Represents a visit of an origin at a given point in time, by a SWH loader.""" - origin = attr.ib(type=Origin) + origin = attr.ib(type=str) date = attr.ib(type=datetime.datetime) status = attr.ib( type=str, @@ -149,7 +149,6 @@ class OriginVisit(BaseModel): d = d.copy() date = d.pop('date') return cls( - origin=Origin.from_dict(d.pop('origin')), date=(date if isinstance(date, datetime.datetime) else dateutil.parser.parse(date)), diff --git a/swh/model/tests/test_model.py b/swh/model/tests/test_model.py index 2900cd1f..f65dd28d 100644 --- a/swh/model/tests/test_model.py +++ b/swh/model/tests/test_model.py @@ -3,7 +3,6 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -import attr import copy from hypothesis import given @@ -44,10 +43,7 @@ def test_todict_origins(origin): def test_todict_origin_visits(origin_visit): obj = origin_visit.to_dict() - assert 'type' not in obj['origin'] - origin2 = attr.evolve(origin_visit.origin, type=None) - origin_visit2 = attr.evolve(origin_visit, origin=origin2) - assert origin_visit2 == type(origin_visit).from_dict(obj) + assert origin_visit == type(origin_visit).from_dict(obj) def test_content_get_hash(): -- GitLab