[schema] Make description level mandatory 0.10.0 centos/0.10.0-1 debian/0.10.0-1
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 30 Mar 2017 18:51:11 +0200
changeset 2567 746ad8fb9838
parent 2566 ea3da4a88df1
child 2568 fb33a8aeb23a
[schema] Make description level mandatory This is an enum in the original xsd while we don't output possible values currently, so in the mean time make it mandatory, it's still a bit better than relying on the original schema for that, and it makes sense from a business POV to force specification of description level of an archive unit. A lot of tests have to be updated, some of them because output value is now different, others because we've to introduce a scheme+concept to handle the validation, but they were not expecting that. Closes #16687907
cubicweb_seda/migration/0.9.1_Any.py
cubicweb_seda/schema/seda2.py
cubicweb_seda/xsd2yams.py
test/data/BV2.0_min.xml
test/data/seda_02_bordereau_ref.xml
test/data/seda_02_export.rng
test/data/seda_02_export.xsd
test/data/seda_1_export.rng
test/data/seda_1_export.xsd
test/test_html_generation.py
test/test_profile_generation.py
test/testutils.py
--- a/cubicweb_seda/migration/0.9.1_Any.py	Fri Mar 31 09:44:00 2017 +0200
+++ b/cubicweb_seda/migration/0.9.1_Any.py	Thu Mar 30 18:51:11 2017 +0200
@@ -25,3 +25,6 @@
     label.cw_set(label=new_label)
     # don't care about migrating updated definition for now
 commit()
+
+
+sync_schema_props_perms('seda_description_level')
--- a/cubicweb_seda/schema/seda2.py	Fri Mar 31 09:44:00 2017 +0200
+++ b/cubicweb_seda/schema/seda2.py	Thu Mar 30 18:51:11 2017 +0200
@@ -1611,7 +1611,7 @@
     name = 'seda_description_level'
     subject = 'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement'
     object = 'Concept'
-    cardinality = '?*'
+    cardinality = '1*'
     composite = fulltext_container = None
     inlined = True
     constraints = [RQLConstraint('O in_scheme CS, CS scheme_relation_type CR, CR name "seda_description_level"')]
--- a/cubicweb_seda/xsd2yams.py	Fri Mar 31 09:44:00 2017 +0200
+++ b/cubicweb_seda/xsd2yams.py	Thu Mar 30 18:51:11 2017 +0200
@@ -202,6 +202,7 @@
     'seda_archive_unit': '?*',
     'seda_binary_data_object': '?*',
     'seda_physical_data_object': '?*',
+    'seda_description_level': '1*',
 }
 RTYPE_CARD = {
     'seda_custodial_history_item': '*',
--- a/test/data/BV2.0_min.xml	Fri Mar 31 09:44:00 2017 +0200
+++ b/test/data/BV2.0_min.xml	Thu Mar 30 18:51:11 2017 +0200
@@ -62,7 +62,7 @@
                     <NeedAuthorization>false</NeedAuthorization>
                 </Management>
                 <Content>
-                    <DescriptionLevel>RecordGrp</DescriptionLevel>
+                    <DescriptionLevel>file</DescriptionLevel>
                     <Title>Versement de la matrice cadastrale numérique</Title>
                     <OriginatingAgencyArchiveUnitIdentifier>frfr</OriginatingAgencyArchiveUnitIdentifier>
                     <TransferringAgencyArchiveUnitIdentifier>xsxsx</TransferringAgencyArchiveUnitIdentifier>
--- a/test/data/seda_02_bordereau_ref.xml	Fri Mar 31 09:44:00 2017 +0200
+++ b/test/data/seda_02_bordereau_ref.xml	Thu Mar 30 18:51:11 2017 +0200
@@ -15,7 +15,7 @@
     <ArchivalAgreement>AccordBordeaux</ArchivalAgreement>
     <!-- <ArchivalProfile>25651/p000035368</ArchivalProfile> -->
     <DescriptionLanguage listVersionID="edition 2009">fr</DescriptionLanguage>
-    <DescriptionLevel listVersionID="edition 2009">series</DescriptionLevel>
+    <DescriptionLevel listVersionID="edition 2009">file</DescriptionLevel>
     <Name>Pewal</Name>
     <TransferringAgencyArchiveIdentifier>75241/a000000039</TransferringAgencyArchiveIdentifier>
     <ContentDescription>
@@ -33,7 +33,7 @@
       <StartDate>2009-07-14</StartDate>
     </AccessRestriction>
     <Contains>
-      <DescriptionLevel listVersionID="edition 2009">item</DescriptionLevel>
+      <DescriptionLevel listVersionID="edition 2009">file</DescriptionLevel>
       <Name>Kesso</Name>
       <TransferringAgencyObjectIdentifier>75241/a000000040</TransferringAgencyObjectIdentifier>
       <ContentDescription>
--- a/test/data/seda_02_export.rng	Fri Mar 31 09:44:00 2017 +0200
+++ b/test/data/seda_02_export.rng	Thu Mar 30 18:51:11 2017 +0200
@@ -378,7 +378,7 @@
                 <rng:attribute name="listVersionID">
                   <rng:value type="token">edition 2009</rng:value>
                 </rng:attribute>
-                <rng:data type="string"/>
+                <rng:value type="string">file</rng:value>
               </rng:element>
               <xsd:annotation>
                 <xsd:documentation>archive unit title</xsd:documentation>
@@ -444,7 +444,7 @@
                 <rng:attribute name="listVersionID">
                   <rng:value type="token">edition 2009</rng:value>
                 </rng:attribute>
-                <rng:data type="string"/>
+                <rng:value type="string">file</rng:value>
               </rng:element>
               <xsd:annotation>
                 <xsd:documentation>archive unit title</xsd:documentation>
--- a/test/data/seda_02_export.xsd	Fri Mar 31 09:44:00 2017 +0200
+++ b/test/data/seda_02_export.xsd	Thu Mar 30 18:51:11 2017 +0200
@@ -280,7 +280,7 @@
                 </xsd:annotation>
                 <xsd:complexType>
                   <xsd:sequence>
-                    <xsd:element name="DescriptionLevel">
+                    <xsd:element fixed="file" name="DescriptionLevel">
                       <xsd:complexType>
                         <xsd:simpleContent>
                           <xsd:extension base="qdt:CodeDescriptionLevelType">
@@ -346,7 +346,7 @@
                 </xsd:annotation>
                 <xsd:complexType>
                   <xsd:sequence>
-                    <xsd:element name="DescriptionLevel">
+                    <xsd:element fixed="file" name="DescriptionLevel">
                       <xsd:complexType>
                         <xsd:simpleContent>
                           <xsd:extension base="qdt:CodeDescriptionLevelType">
--- a/test/data/seda_1_export.rng	Fri Mar 31 09:44:00 2017 +0200
+++ b/test/data/seda_1_export.rng	Thu Mar 30 18:51:11 2017 +0200
@@ -388,7 +388,7 @@
                   <rng:attribute name="listVersionID">
                     <rng:value type="token">edition 2009</rng:value>
                   </rng:attribute>
-                  <rng:data type="string"/>
+                  <rng:value type="string">file</rng:value>
                 </rng:element>
                 <rng:element name="Language">
                   <rng:attribute name="listVersionID">
@@ -467,7 +467,7 @@
                   <rng:attribute name="listVersionID">
                     <rng:value type="token">edition 2009</rng:value>
                   </rng:attribute>
-                  <rng:data type="string"/>
+                  <rng:value type="string">file</rng:value>
                 </rng:element>
                 <rng:element name="Language">
                   <rng:attribute name="listVersionID">
--- a/test/data/seda_1_export.xsd	Fri Mar 31 09:44:00 2017 +0200
+++ b/test/data/seda_1_export.xsd	Thu Mar 30 18:51:11 2017 +0200
@@ -269,7 +269,7 @@
                     <xsd:element name="ContentDescription">
                       <xsd:complexType>
                         <xsd:sequence>
-                          <xsd:element name="DescriptionLevel">
+                          <xsd:element fixed="file" name="DescriptionLevel">
                             <xsd:complexType>
                               <xsd:simpleContent>
                                 <xsd:extension base="qdt:CodeDescriptionLevelType">
@@ -351,7 +351,7 @@
                     <xsd:element name="ContentDescription">
                       <xsd:complexType>
                         <xsd:sequence>
-                          <xsd:element name="DescriptionLevel">
+                          <xsd:element fixed="file" name="DescriptionLevel">
                             <xsd:complexType>
                               <xsd:simpleContent>
                                 <xsd:extension base="qdt:CodeDescriptionLevelType">
--- a/test/test_html_generation.py	Fri Mar 31 09:44:00 2017 +0200
+++ b/test/test_html_generation.py	Thu Mar 30 18:51:11 2017 +0200
@@ -33,7 +33,8 @@
     def setup_database(self):
         super(SEDAHTMLExportFuncTC, self).setup_database()
         with self.admin_access.client_cnx() as cnx:
-            some_concept = cnx.find('Concept').one()
+            scheme = cnx.find('ConceptScheme', title=u'Keyword Types').one()
+            some_concept = scheme.reverse_in_scheme[0]
             lang_rtype = cnx.find('CWRType', name='seda_language_to').one()
             some_concept.scheme.cw_set(scheme_relation_type=lang_rtype)
             cnx.find('SEDALanguage').one().cw_set(seda_language_to=some_concept)
@@ -42,6 +43,8 @@
                 seda_keyword_reference_to_scheme=some_concept.scheme)
             cnx.commit()
 
+        self.concept_eid = some_concept.eid
+
     def assertXmlValid(self, root):
         pass  # no schema available for html 5
 
@@ -66,7 +69,7 @@
     def test_profile1(self):
         with self.admin_access.client_cnx() as cnx:
             transfer = cnx.entity_from_eid(self.transfer_eid)
-            some_concept = cnx.find('Concept').one()
+            some_concept = cnx.entity_from_eid(self.concept_eid)
             profile = self.profile_etree(transfer)
             # ensure encoding is declared
             meta = self.xpath(profile, '/html/head/meta')[0]
--- a/test/test_profile_generation.py	Fri Mar 31 09:44:00 2017 +0200
+++ b/test/test_profile_generation.py	Thu Mar 30 18:51:11 2017 +0200
@@ -645,7 +645,7 @@
     def test_profile1(self):
         """Check a minimal SEDA profile validating BV2.0_min.xml."""
         with self.admin_access.client_cnx() as cnx:
-            mda_scheme = cnx.execute('ConceptScheme X').one()
+            mda_scheme = cnx.find('ConceptScheme', title=u'Keyword Types').one()
             transfer = cnx.entity_from_eid(self.transfer_eid)
             root = self.profile_etree(transfer)
         self.check_xsd_profile(root, self.datapath('BV2.0_min.xml'),
@@ -737,8 +737,7 @@
             _, _, unit_alt_seq = testutils.create_archive_unit(transfer,
                                                                user_cardinality=u'1..n')
 
-            unit_alt_seq.cw_set(seda_description_level=concepts['file'],
-                                reverse_seda_start_date=create('SEDAStartDate',
+            unit_alt_seq.cw_set(reverse_seda_start_date=create('SEDAStartDate',
                                                                user_cardinality=u'0..1'),
                                 reverse_seda_end_date=create('SEDAEndDate'),
                                 # XXX, value=date(2015, 2, 24)),
--- a/test/testutils.py	Fri Mar 31 09:44:00 2017 +0200
+++ b/test/testutils.py	Thu Mar 30 18:51:11 2017 +0200
@@ -15,6 +15,8 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """Miscellaneous test utilities."""
 
+from cubicweb.rset import NoResultError
+
 
 def create_transfer_to_bdo(cnx):
     """Create minimal ArchiveTransfer down to a BinaryDataObject and return the later."""
@@ -40,9 +42,16 @@
     if archive_unit_reference:
         last = cnx.create_entity('SEDAArchiveUnitRefId', seda_archive_unit_ref_id_from=alt)
     else:
+        try:
+            description_level = cnx.execute('Concept C WHERE L label_of C, L label "file"').one()
+        except NoResultError:
+            with cnx.security_enabled(write=False):
+                scheme = scheme_for_type(cnx, 'seda_description_level', None, u'file')
+                description_level = scheme.reverse_in_scheme[0]
         last = cnx.create_entity(
             'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement',
-            reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management=alt)
+            reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management=alt,
+            seda_description_level=description_level)
         cnx.create_entity('SEDATitle', seda_title=last, title=title)
 
     return au, alt, last