[PATCH seda] [profile gen] Ensure data-objects are exported before sub-units

Sylvain Thénault sylvain.thenault at logilab.fr
Tue Aug 29 17:31:31 CEST 2017


this patch breaks CI, will send a v2


On 29/08/2017 16:37, Sylvain Thenault wrote:
>  cubicweb_seda/entities/profile_generation.py |   4 +++-
>  test/test_profile_generation.py              |  22 ++++++++++++++++++++++
>  2 files changed, 25 insertions(+), 1 deletions(-)
>
>
> # HG changeset patch
> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
> # Date 1504017381 -7200
> #      Tue Aug 29 16:36:21 2017 +0200
> # Node ID 815d0483d4c48fd3942d24712e8d74ee5d0277f5
> # Parent  274dcd2aafbfcb7a6cd864e039e6cf4b4918fb17
> # Available At https://hg.logilab.org/review/cubes/seda
> #              hg pull https://hg.logilab.org/review/cubes/seda -r 815d0483d4c4
> [profile gen] Ensure data-objects are exported before sub-units
>
> else this won't be conform to SEDA 0.2/1.0 schema.
>
> Closes extranet #33070904
>
> diff --git a/cubicweb_seda/entities/profile_generation.py b/cubicweb_seda/entities/profile_generation.py
> --- a/cubicweb_seda/entities/profile_generation.py
> +++ b/cubicweb_seda/entities/profile_generation.py
> @@ -816,11 +816,13 @@ class SEDA1XSDExport(SEDA2ExportAdapter)
>  
>      def xsd_children(self, parent, entity):
>          """Iter on archive/archive object children, which may be either
>          archive objects or documents, and append XSD elements for them to the given parent node.
>          """
> -        for au_or_bdo in entity.cw_adapt_to('ITreeBase').iterchildren():
> +        for au_or_bdo in sorted(entity.cw_adapt_to('ITreeBase').iterchildren(),
> +                                # ensure we get data object first
> +                                key=lambda x: x.cw_etype == 'SEDAArchiveUnit'):
>              if au_or_bdo.cw_etype == 'SEDABinaryDataObject':
>                  self.xsd_document(parent, au_or_bdo)
>              else:
>                  assert au_or_bdo.cw_etype == 'SEDAArchiveUnit'
>                  self.xsd_archive_object(parent, au_or_bdo)
> diff --git a/test/test_profile_generation.py b/test/test_profile_generation.py
> --- a/test/test_profile_generation.py
> +++ b/test/test_profile_generation.py
> @@ -915,10 +915,32 @@ class OldSEDARNGExportTC(RelaxNGTestMixi
>              cnx.commit()
>  
>              root = self.profile_etree(transfer, 'SEDA-0.2.rng')
>          self.check_xsd_profile(root, self.datapath('seda_02_bordereau_ref.xml'))
>  
> +    def test_children_order(self):
> +        with self.admin_access.cnx() as cnx:
> +            create = cnx.create_entity
> +
> +            transfer = create('SEDAArchiveTransfer', title=u'test profile',
> +                              simplified_profile=True)
> +            unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(transfer)
> +            subunit, subunit_alt, subunit_alt_seq = testutils.create_archive_unit(
> +                unit_alt_seq)
> +            bdo = testutils.create_data_object(transfer)
> +            create('SEDADataObjectReference',
> +                   seda_data_object_reference=unit_alt_seq,
> +                   seda_data_object_reference_id=bdo)
> +            cnx.commit()
> +
> +            adapter = transfer.cw_adapt_to('SEDA-0.2.xsd')
> +            root = etree.Element('test-root')
> +            adapter.xsd_children(root, unit)
> +
> +        # ensure Document appears before Contains
> +        self.assertEqual([node.attrib['name'] for node in root], ['Document', 'Contains'])
> +
>  
>  class SEDAExportUnitTest(unittest.TestCase):
>  
>      def test_concepts_languages(self):
>          self.assertEqual(pg.SEDA1XSDExport.concepts_language, 'seda-1')
>

-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the saem-devel mailing list