[test] Add a test for ITreeBase behaviour on regular and simplified profiles
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 25 Aug 2016 17:52:44 +0200
changeset 1573 bc6f8557fc81
parent 1572 7c37ce56f26d
child 1574 b26ac24f94f4
[test] Add a test for ITreeBase behaviour on regular and simplified profiles
test/test_entities.py
--- a/test/test_entities.py	Thu Aug 25 18:03:23 2016 +0200
+++ b/test/test_entities.py	Thu Aug 25 17:52:44 2016 +0200
@@ -19,6 +19,8 @@
 
 from cubes.seda.entities import seda_profile_container_def, simplified_profile, full_seda2_profile
 
+from testutils import create_archive_unit, create_data_object
+
 
 def sort_container(container_def):
     for k, v in container_def:
@@ -97,6 +99,54 @@
             self.assertEqual(simplified_profile_pred(None, req, entity=transfer), 1)
             self.assertEqual(full_seda2_profile_pred(None, req, entity=transfer), 0)
 
+
+class ITreeTC(CubicWebTC):
+
+    def assertChildren(self, entity, expected_eids):
+        itree = entity.cw_adapt_to('ITreeBase')
+        children = [x.eid for x in itree.iterchildren()]
+        self.assertEqual(children, expected_eids)
+
+    def assertParent(self, entity, expected_eid):
+        itree = entity.cw_adapt_to('ITreeBase')
+        parent = itree.parent()
+        if parent:
+            parent_eid = parent.eid
+        else:
+            parent_eid = None
+        self.assertEqual(parent_eid, expected_eid)
+
+    def test(self):
+        with self.admin_access.client_cnx() as cnx:
+            transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
+            au, alt, seq = create_archive_unit(transfer)
+            do_ref = cnx.create_entity('SEDADataObjectReference',
+                                       seda_data_object_reference=seq)
+            bdo = create_data_object(transfer,
+                                     reverse_seda_data_object_reference_id=do_ref)
+            cnx.commit()
+            content = seq.reverse_seda_content[0]
+            au.cw_clear_all_caches()
+            bdo.cw_clear_all_caches()
+
+            self.assertChildren(transfer, [bdo.eid, au.eid])
+            self.assertChildren(au, [content.eid])
+            self.assertParent(transfer, None)
+            self.assertParent(au, transfer.eid)
+            self.assertParent(bdo, transfer.eid)
+
+            transfer.cw_set(simplified_profile=True)
+            cnx.commit()
+            au.cw_clear_all_caches()
+            bdo.cw_clear_all_caches()
+
+            self.assertChildren(transfer, [au.eid])
+            self.assertChildren(au, [bdo.eid])
+            self.assertParent(transfer, None)
+            self.assertParent(au, transfer.eid)
+            self.assertParent(bdo, au.eid)
+
+
 if __name__ == '__main__':
     import unittest
     unittest.main()