[profile gen] Make archive unit and data object's 'id' and associated reference mandatory
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 10 Nov 2016 10:33:42 +0100
changeset 1970 b92844790328
parent 1969 40e17295c68b
child 1971 2702a778d9d4
[profile gen] Make archive unit and data object's 'id' and associated reference mandatory Those special attribute / content values should be explicitly typed using xsd's ID and IDREF respectivly. Closes #16070553
entities/profile_generation.py
test/test_profile_generation.py
--- a/entities/profile_generation.py	Wed Nov 09 17:33:46 2016 +0100
+++ b/entities/profile_generation.py	Thu Nov 10 10:33:42 2016 +0100
@@ -679,6 +679,7 @@
         if fixed_value is not None:
             if hasattr(value, 'id'):
                 profile_element.attrib[self.qname('a:defaultValue')] = fixed_value
+                self.element('rng:data', profile_element, {'type': 'IDREF'})
             else:
                 if (len(profile_element)
                         and profile_element[-1].tag == '{http://relaxng.org/ns/structure/1.0}data'):
@@ -721,6 +722,7 @@
             if value is not None:
                 if xselement.local_name == 'id':
                     attr_element.attrib[self.qname('seda:profid')] = value
+                    self.element('rng:data', attr_element, {'type': 'ID'})
                 else:
                     self.element('rng:value', attr_element, {'type': xstype}, text=value)
             else:
--- a/test/test_profile_generation.py	Wed Nov 09 17:33:46 2016 +0100
+++ b/test/test_profile_generation.py	Thu Nov 10 10:33:42 2016 +0100
@@ -636,10 +636,13 @@
     def assertProfileDetails(self, root):
         # ensure profile's temporary id are exported in custom seda:profid attribute
         self.assertEqual(len(self.xpath(root, '//rng:attribute[@seda:profid]')), 2)
+        for attrdef in self.xpath(root, '//xs:attribute[@seda:profid]'):
+            self.assertEqual(attrdef[0]['type'], 'ID')
         # ensure they are properly referenced using 'default' attribute
         references = self.xpath(root, '//rng:element[@a:defaultValue="bdo1"]')
         self.assertEqual(len(references), 1)
         self.assertEqual(references[0].attrib['name'], 'DataObjectReferenceId')
+        self.assertEqual(references[0][0].attrib['type'], 'IDREF')
         # ensure optional id are properly reinjected
         references = self.xpath(root,
                                 '//rng:element[@name="Keyword"]/rng:optional'