[entities] Fix ITree of simplified profile to return children properly ordered
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 07 Dec 2017 11:05:39 +0100
changeset 2902 497653f15d88
parent 2901 c5c5d8ea25b9
child 2903 0d93e3addfc5
[entities] Fix ITree of simplified profile to return children properly ordered based on reference's ordering attribute. Use the reference and not the data object's ordering because it's the one used on the data objects tab for simplified profiles.
cubicweb_seda/entities/itree.py
test/test_entities.py
--- a/cubicweb_seda/entities/itree.py	Thu Dec 07 11:04:18 2017 +0100
+++ b/cubicweb_seda/entities/itree.py	Thu Dec 07 11:05:39 2017 +0100
@@ -109,7 +109,7 @@
         seq = self.entity.first_level_choice.content_sequence
         assert seq is not None, self.entity  # can't be None in simplified profile
         for do in self._cw.execute(
-                'Any DO, DOUA ORDERBY DOUA WHERE DO user_annotation DOUA, '
+                'Any DO, DOUA ORDERBY REFO WHERE DO user_annotation DOUA, REF ordering REFO, '
                 'REF seda_data_object_reference_id DO, '
                 'REF seda_data_object_reference SEQ, SEQ eid %(x)s',
                 {'x': seq.eid}).entities():
--- a/test/test_entities.py	Thu Dec 07 11:04:18 2017 +0100
+++ b/test/test_entities.py	Thu Dec 07 11:05:39 2017 +0100
@@ -234,13 +234,18 @@
         with self.admin_access.cnx() as cnx:
             transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
             au, alt, seq = create_archive_unit(transfer)
+            au2 = create_archive_unit(transfer)[0]
             do_ref = cnx.create_entity('SEDADataObjectReference',
                                        seda_data_object_reference=seq)
             bdo = create_data_object(transfer,
                                      reverse_seda_data_object_reference_id=do_ref)
+            do_ref2 = cnx.create_entity('SEDADataObjectReference',
+                                        seda_data_object_reference=seq)
+            bdo2 = create_data_object(transfer,
+                                      reverse_seda_data_object_reference_id=do_ref2)
             cnx.commit()
 
-            self.assertChildren(transfer, [bdo.eid, au.eid])
+            self.assertChildren(transfer, [bdo.eid, bdo2.eid, au.eid, au2.eid])
             self.assertChildren(au, [])
             self.assertParent(transfer, None)
             self.assertParent(au, transfer.eid)
@@ -249,12 +254,28 @@
             transfer.cw_set(simplified_profile=True)
             cnx.commit()
 
-            self.assertChildren(transfer, [au.eid])
-            self.assertChildren(au, [bdo.eid])
+            self.assertChildren(transfer, [au.eid, au2.eid])
+            self.assertChildren(au, [bdo.eid, bdo2.eid])
             self.assertParent(transfer, None)
             self.assertParent(au, transfer.eid)
             self.assertParent(bdo, au.eid)
 
+            au.cw_set(ordering=2)
+            au2.cw_set(ordering=1)
+            bdo.cw_set(ordering=2)
+            bdo2.cw_set(ordering=1)
+            do_ref.cw_set(ordering=2)
+            do_ref2.cw_set(ordering=1)
+            cnx.commit()
+
+            self.assertChildren(transfer, [au2.eid, au.eid])
+            self.assertChildren(au, [bdo2.eid, bdo.eid])
+
+            transfer.cw_set(simplified_profile=False)
+            cnx.commit()
+
+            self.assertChildren(transfer, [bdo2.eid, bdo.eid, au2.eid, au.eid])
+
 
 class RuleFromETypeTC(unittest.TestCase):
     def test_rule_from_etype(self):