From 6ce0f71458d40be24c419b8a0d0525c12550840d Mon Sep 17 00:00:00 2001
From: David Douard <david.douard@sdfa3.org>
Date: Mon, 23 Mar 2020 10:27:52 +0100
Subject: [PATCH] model: fix SkippedContent origin to be a str

instead of a reference to an Origin entity.
---
 swh/model/model.py            |  2 +-
 swh/model/tests/test_model.py | 20 +++++++++++++++++---
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/swh/model/model.py b/swh/model/model.py
index 6fdfe329..f6e8a5ba 100644
--- a/swh/model/model.py
+++ b/swh/model/model.py
@@ -681,7 +681,7 @@ class SkippedContent(BaseContent):
         default=None)
 
     origin = attr.ib(
-        type=Optional[Origin],
+        type=Optional[str],
         validator=type_validator(),
         default=None)
 
diff --git a/swh/model/tests/test_model.py b/swh/model/tests/test_model.py
index e167d5a7..4bbb1d07 100644
--- a/swh/model/tests/test_model.py
+++ b/swh/model/tests/test_model.py
@@ -14,15 +14,15 @@ import pytest
 
 from swh.model.model import (
     Content, SkippedContent, Directory, Revision, Release, Snapshot,
-    Timestamp, TimestampWithTimezone,
+    Origin, Timestamp, TimestampWithTimezone,
     MissingData, Person
 )
 from swh.model.hashutil import hash_to_bytes, MultiHash
 
 from swh.model.hypothesis_strategies import (
-    objects, origins, origin_visits, origin_visit_updates, timestamps
+    objects, origins, origin_visits, origin_visit_updates,
+    skipped_contents_d, timestamps
 )
-
 from swh.model.identifiers import (
     directory_identifier, revision_identifier, release_identifier,
     snapshot_identifier
@@ -386,6 +386,20 @@ def test_skipped_content_from_data(data):
         assert getattr(c, key) == value
 
 
+@given(skipped_contents_d())
+def test_skipped_content_origin_is_str(skipped_content_d):
+    assert SkippedContent.from_dict(skipped_content_d)
+
+    skipped_content_d['origin'] = 'http://path/to/origin'
+    assert SkippedContent.from_dict(skipped_content_d)
+
+    skipped_content_d['origin'] = Origin(url='http://path/to/origin')
+    with pytest.raises(ValueError, match='origin'):
+        SkippedContent.from_dict(skipped_content_d)
+
+
+# ID computation
+
 def test_directory_model_id_computation():
     dir_dict = directory_example.copy()
     del dir_dict['id']
-- 
GitLab