[profile scheme] Use the cwuri_url static method to generate URLs for SEDA 2 export
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 30 Mar 2017 17:21:52 +0200
changeset 2564 dd0fa3ba2760
parent 2563 455ce14bb7bf
child 2565 3da29cc2d6c8
[profile scheme] Use the cwuri_url static method to generate URLs for SEDA 2 export as this was already done for SEDA 1/0.2 export. Move method from SEDA 1 export to the common base class with SEDA 2 export to make it available there and avoid duplication. Also SEDA 2 test needs update since this method return cwuri instead of absolute_url. Related to extranet #15934739
cubicweb_seda/entities/profile_generation.py
test/test_profile_generation.py
--- a/cubicweb_seda/entities/profile_generation.py	Thu Mar 30 16:38:47 2017 +0200
+++ b/cubicweb_seda/entities/profile_generation.py	Thu Mar 30 17:21:52 2017 +0200
@@ -103,13 +103,13 @@
     return 'id' + text_type(eid)
 
 
-def serialize(value):
+def serialize(value, build_url):
     """Return typed `value` as an XSD string."""
     if value is None:
         return None
     if hasattr(value, 'eid'):
         if value.cw_etype == 'ConceptScheme':
-            return value.absolute_url()
+            return build_url(value)
         if value.cw_etype == 'Concept':
             return _concept_value(value, 'seda-2')
         if _internal_reference(value):
@@ -368,6 +368,14 @@
         """Return the last generated element, for insertion of its content."""
         raise NotImplementedError()
 
+    @staticmethod
+    def cwuri_url(entity):
+        """Return "public" URI for the given entity.
+
+        In a staticmethod to ease overriding in subclasses (eg saem).
+        """
+        return entity.cwuri
+
 
 class SEDA2RelaxNGExport(RNGMixin, SEDA2ExportAdapter):
     """Adapter to build a Relax NG representation of a SEDA profile, using SEDA 2.0 specification.
@@ -471,7 +479,7 @@
 
     def element_xmlattribute(self, occ, profile_element, target_value, to_process, card_entity):
         parent_element = self._rng_attribute_parent(occ, card_entity, profile_element)
-        self._rng_attribute(occ.target, parent_element, serialize(target_value))
+        self._rng_attribute(occ.target, parent_element, serialize(target_value, self.cwuri_url))
 
     def element_xmlelement(self, occ, profile_element, target_value, to_process, card_entity):  # noqa
         parent_element = self._rng_element_parent(occ, card_entity, profile_element)
@@ -530,7 +538,7 @@
                 if attrname in ('id', 'href') or attrname.startswith(('list', 'scheme')):
                     parent_element = self._rng_attribute_parent(occ, None, profile_element)
                     self._rng_attribute(occ.target, parent_element)
-        fixed_value = serialize(value)
+        fixed_value = serialize(value, self.cwuri_url)
         if fixed_value is not None:
             if _internal_reference(value):
                 profile_element.attrib[self.qname('a:defaultValue')] = fixed_value
@@ -552,12 +560,12 @@
             return
         scheme_attr = self.element('rng:attribute', type_element,
                                    attributes={'name': scheme_attr})
-        self.element('rng:value', scheme_attr, text=scheme.absolute_url())
+        self.element('rng:value', scheme_attr, text=self.cwuri_url(scheme))
 
     def fill_organization_element(self, parent_element, value):
         target_element = self.element('rng:element', parent_element, {'name': 'Identifier'})
         if value:
-            self.element('rng:value', target_element, text=value.absolute_url())
+            self.element('rng:value', target_element, text=self.cwuri_url(value))
 
     def _rng_element_parent(self, occ, card_entity, profile_element):
         minimum, maximum = element_minmax_cardinality(occ, card_entity)
@@ -1100,14 +1108,6 @@
         return (data_object.cw_adapt_to('ITreeBase').parent().first_level_choice.content_sequence
                 .system_id)
 
-    @staticmethod
-    def cwuri_url(entity):
-        """Return "public" URI for the given entity.
-
-        In a staticmethod to ease overriding in subclasses (eg saem).
-        """
-        return entity.cwuri
-
 
 class SEDA02XSDExport(SEDA1XSDExport):
     """Adapter to build an XSD representation of a SEDA profile, using SEDA 0.2 specification"""
--- a/test/test_profile_generation.py	Thu Mar 30 16:38:47 2017 +0200
+++ b/test/test_profile_generation.py	Thu Mar 30 17:21:52 2017 +0200
@@ -488,7 +488,7 @@
                                                'type': 'xsd:token'})
             self.assertXSDAttributes(
                 kwr,
-                [{'name': 'schemeURI', 'fixed': scheme.absolute_url()}])
+                [{'name': 'schemeURI', 'fixed': scheme.cwuri}])
 
             kwr_e.cw_set(seda_keyword_reference_to=kw_type)
             profile = self.profile_etree(transfer)
@@ -498,7 +498,7 @@
                                                'fixed': 'theme'})
             self.assertXSDAttributes(
                 kwr,
-                [{'name': 'schemeURI', 'fixed': scheme.absolute_url()}])
+                [{'name': 'schemeURI', 'fixed': scheme.cwuri}])
 
     def test_code_list(self):
         with self.admin_access.client_cnx() as cnx:
@@ -511,7 +511,7 @@
             profile = self.profile_etree(transfer)
             mt_clv = self.get_element(profile, 'MimeTypeCodeListVersion')
             self.assertElementDefinition(mt_clv, {'name': 'MimeTypeCodeListVersion',
-                                                  'fixed': scheme.absolute_url(),
+                                                  'fixed': scheme.cwuri,
                                                   'type': 'xsd:token',
                                                   'minOccurs': '0'})
             # XXX also fix listSchemeURI ?
@@ -649,7 +649,7 @@
             transfer = cnx.entity_from_eid(self.transfer_eid)
             root = self.profile_etree(transfer)
         self.check_xsd_profile(root, self.datapath('BV2.0_min.xml'),
-                               mda_scheme_url=mda_scheme.absolute_url())
+                               mda_scheme_url=mda_scheme.cwuri)
         # ensure jumped element without content are not there
         self.assertEqual(len(self.get_elements(root, 'Gps')), 0)
         # ensure element with skipped value are not there