[PATCH 2 of 7 saem_ref V2] [seda] Ensure URLs generated for different SEDA versions are consistent

Sylvain Thenault sylvain.thenault at logilab.fr
Mon Apr 10 14:50:42 CEST 2017

# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490888010 -7200
#      Thu Mar 30 17:33:30 2017 +0200
# Node ID eacf1752ed3d04c6f017a24544140060a455814a
# Parent  b8599a52fa6dd09ce1b4457840a9ecb3179a1eb5
[seda] Ensure URLs generated for different SEDA versions are consistent

In saem_ref, we want all entities that have an ark to have an URL built using
this ark. This is ensured by the the `cwuri_url` function, which was
considered by the SEDA 1 / 0.2 export adapter but not by the SEDA 2 adapter.

Since refactoring in the seda cube, we may simply patch the common base class
instead of SEDA 1 adapter class.

Related to extranet #15934739

diff --git a/cubicweb_saem_ref/entities/seda.py b/cubicweb_saem_ref/entities/seda.py
--- a/cubicweb_saem_ref/entities/seda.py
+++ b/cubicweb_saem_ref/entities/seda.py
@@ -22,18 +22,21 @@ from cubicweb.predicates import is_insta
 from cubes.oaipmh import MetadataFormat
 from cubes.oaipmh.entities import OAISetSpec
 from cubicweb_seda.entities import SEDAArchiveTransferIClonableAdapter
 from cubicweb_seda.entities.custom import SEDAArchiveTransfer
-from cubicweb_seda.entities.profile_generation import SEDA1XSDExport
+from cubicweb_seda.entities.profile_generation import SEDA2ExportAdapter, SEDA1XSDExport
 from cubicweb_seda.views import export
 from .. import cwuri_url
 from . import oai
-SEDA1XSDExport.cwuri_url = staticmethod(cwuri_url)
+# monkeypatch cwuri_url method instead of subclassing and replacing adapters because there are 5 of
+# them impacted (SEDA 2 rng, 1/0.2 rng/xsd) while we may change it once for all on the common base
+# class
+SEDA2ExportAdapter.cwuri_url = staticmethod(cwuri_url)
 # hijack xsd_archival_agreement to insert profile as well. Use a monkey-patch rather than new
 # implementation to avoid doing it twice, once for SEDA 1 another for SEDA 0.2
diff --git a/test/test_seda.py b/test/test_seda.py
--- a/test/test_seda.py
+++ b/test/test_seda.py
@@ -17,11 +17,11 @@
 import unittest
 from cubicweb.devtools.testlib import CubicWebTC
-from cubicweb_seda.entities.profile_generation import SEDA1XSDExport
+from cubicweb_seda.entities.profile_generation import SEDA1XSDExport, SEDA2RelaxNGExport
 from cubicweb_saem_ref.entities import seda  # noqa - trigger monkey-patch
 import testutils
@@ -45,10 +45,19 @@ class CWURIURLTC(unittest.TestCase):
+        self.assertEqual(SEDA2RelaxNGExport.cwuri_url(FakeEntity('ark:12/3')),
+                         'http://thistest/ark:12/3')
+        self.assertEqual(SEDA2RelaxNGExport.cwuri_url(FakeEntity('http://othertest/ark:12/3')),
+                         'http://othertest/ark:12/3')
+        self.assertEqual(SEDA2RelaxNGExport.cwuri_url(FakeEntity('http://othertest/whatever')),
+                         'http://othertest/whatever')
+        self.assertEqual(SEDA2RelaxNGExport.cwuri_url(FakeEntity('whatever')),
+                         'whatever')
 class SEDAExportTC(CubicWebTC):
     def test_include_profile_ark(self):
         with self.admin_access.client_cnx() as cnx:

More information about the saem-devel mailing list