[PATCH 3 of 5 seda] [entities] Make _climb_rule_holders working on SEDASeqAltArchiveUnitArchiveUnitRefIdManagement entities

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 17 10:45:11 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489740952 -3600
#      Fri Mar 17 09:55:52 2017 +0100
# Node ID 3c65e089271ed20fad54c3fb0115f16980e2e055
# Parent  da6b373bb952a31b906eae3ec11f0b31ff041f9b
[entities] Make _climb_rule_holders working on SEDASeqAltArchiveUnitArchiveUnitRefIdManagement entities

This will be useful in later cset to add inherited_rule method on this entity
type.

diff --git a/cubicweb_seda/entities/custom.py b/cubicweb_seda/entities/custom.py
--- a/cubicweb_seda/entities/custom.py
+++ b/cubicweb_seda/entities/custom.py
@@ -13,11 +13,11 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 
 from ..xsd2yams import RULE_TYPES
-from . import generated
+from . import generated, itree
 
 
 def _extract_title(annotation):
     """Return the first line in the annotation to use as a title"""
     annotation = annotation.strip()
@@ -28,11 +28,14 @@ def _extract_title(annotation):
 def _climb_rule_holders(transfer_or_archive_unit):
     """Starting from a transfer or archive unit entity, yield entity that may be linked to
     management rule until the root (transfer) is reached.
     """
     while transfer_or_archive_unit is not None:
-        if transfer_or_archive_unit.cw_etype == 'SEDAArchiveTransfer':
+        if transfer_or_archive_unit.cw_etype == 'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement':
+            yield transfer_or_archive_unit
+            transfer_or_archive_unit = itree.parent_archive_unit(transfer_or_archive_unit)
+        elif transfer_or_archive_unit.cw_etype == 'SEDAArchiveTransfer':
             yield transfer_or_archive_unit
         else:
             yield transfer_or_archive_unit.first_level_choice.content_sequence
         transfer_or_archive_unit = transfer_or_archive_unit.cw_adapt_to('ITreeBase').parent()
 
diff --git a/cubicweb_seda/i18n/fr.po b/cubicweb_seda/i18n/fr.po
--- a/cubicweb_seda/i18n/fr.po
+++ b/cubicweb_seda/i18n/fr.po
@@ -7849,11 +7849,13 @@ msgstr ""
 
 msgid "select a type to filter out unrelated vocabularies"
 msgstr "sélectionnez un type pour filtrer les vocabulaires correspondants"
 
 msgid "select first a vocabulary then type here to prompt auto-completion"
-msgstr "sélectionnez un vocabulaire avant de taper dans ce champ pour activer la complétion automatique"
+msgstr ""
+"sélectionnez un vocabulaire avant de taper dans ce champ pour activer la "
+"complétion automatique"
 
 msgid "service_level"
 msgstr "valeur"
 
 msgctxt "SEDAServiceLevel"
diff --git a/test/test_entities.py b/test/test_entities.py
--- a/test/test_entities.py
+++ b/test/test_entities.py
@@ -24,11 +24,11 @@ from logilab.common import attrdict
 
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubicweb_seda.entities import (seda_profile_container_def, simplified_profile,
                                     full_seda2_profile, parent_and_container,
-                                    rule_type_from_etype)
+                                    rule_type_from_etype, custom)
 
 from testutils import create_archive_unit, create_data_object
 
 
 def sort_container(container_def):
@@ -296,8 +296,26 @@ class CustomEntitiesTC(CubicWebTC):
         with self.admin_access.client_cnx() as cnx:
             for etype in ('SEDAArchiveUnit', 'SEDABinaryDataObject', 'SEDAPhysicalDataObject'):
                 ent = cnx.create_entity(etype, user_annotation=u'bla bla\nbli bli blo\n')
                 self.assertEqual(ent.dc_title(), u'bla bla')
 
+    def test_climb_rule_holders(self):
+        with self.admin_access.client_cnx() as cnx:
+            transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
+            unit, _, unit_alt_seq = create_archive_unit(transfer)
+            subunit, _, subunit_alt_seq = create_archive_unit(unit_alt_seq)
+            cnx.commit()
+
+            self.assertEqual(list(custom._climb_rule_holders(subunit_alt_seq)),
+                             [subunit_alt_seq, unit_alt_seq, transfer])
+            self.assertEqual(list(custom._climb_rule_holders(subunit)),
+                             [subunit_alt_seq, unit_alt_seq, transfer])
+            self.assertEqual(list(custom._climb_rule_holders(unit_alt_seq)),
+                             [unit_alt_seq, transfer])
+            self.assertEqual(list(custom._climb_rule_holders(unit)),
+                             [unit_alt_seq, transfer])
+            self.assertEqual(list(custom._climb_rule_holders(transfer)),
+                             [transfer])
+
 
 if __name__ == '__main__':
     unittest.main()


More information about the saem-devel mailing list