[hooks / test] Extract setup_database from DispatchFileCategoryTC's test
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 03 Nov 2017 12:01:15 +0100
changeset 2864 11196b772ee1
parent 2863 33b32481052f
child 2865 5d0adc66a950
[hooks / test] Extract setup_database from DispatchFileCategoryTC's test A new one sharing the setup will be introduced in later cset. Related to #39322647
test/test_hooks.py
--- a/test/test_hooks.py	Fri Nov 03 11:56:48 2017 +0100
+++ b/test/test_hooks.py	Fri Nov 03 12:01:15 2017 +0100
@@ -217,8 +217,7 @@
 
 
 class DispatchFileCategoryTC(CubicWebTC):
-
-    def test(self):
+    def setup_database(self):
         with self.admin_access.cnx() as cnx:
             testutils.scheme_for_type(cnx, 'seda_format_id_to', None,
                                       u'fmt/37', u'fmt/38', u'fmt/14')
@@ -229,9 +228,9 @@
                 (u'Categories de fichier',
                  'file_category', (),
                  join(dirname(__file__), 'data', 'file_categories.csv'))])
-            categories = dict(cnx.execute('Any LL, C WHERE L label_of C, L label LL, '
-                                          'C in_scheme CS, CS title "Categories de fichier"'))
-
+            self.categories = dict(cnx.execute(
+                'Any LL, C WHERE L label_of C, L label LL, '
+                'C in_scheme CS, CS title "Categories de fichier"'))
             transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile',
                                          simplified_profile=True)
             unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(transfer)
@@ -239,7 +238,17 @@
                                                seda_binary_data_object=transfer)
             cnx.commit()
 
-            bdo.cw_set(file_category=categories['document'])
+        self.transfer_eid = transfer.eid
+        self.unit_alt_seq_eid = unit_alt_seq.eid
+        self.bdo_eid = bdo.eid
+
+    def test_base(self):
+        with self.admin_access.cnx() as cnx:
+            transfer = cnx.entity_from_eid(self.transfer_eid)
+            unit_alt_seq = cnx.entity_from_eid(self.unit_alt_seq_eid)
+            bdo = cnx.entity_from_eid(self.bdo_eid)
+
+            bdo.cw_set(file_category=self.categories['document'])
             cnx.commit()
             self.assertFormatEqual(bdo,
                                    ['application/msword', 'application/pdf'],
@@ -249,7 +258,7 @@
             cnx.commit()
             self.assertFormatEqual(bdo, [], [])
 
-            bdo.cw_set(file_category=categories['doc'])
+            bdo.cw_set(file_category=self.categories['doc'])
             cnx.commit()
             self.assertFormatEqual(bdo,
                                    ['application/msword'],
@@ -261,7 +270,7 @@
             bdo_comp = testutils.create_data_object(unit_comp_alt_seq)
             cnx.commit()
 
-            bdo_comp.cw_set(file_category=categories['document'])
+            bdo_comp.cw_set(file_category=self.categories['document'])
             cnx.commit()
             self.assertFormatEqual(bdo_comp,
                                    [],
@@ -269,7 +278,6 @@
             # until it's imported into some parent
             copy_entity(unit_comp, seda_archive_unit=unit_alt_seq, clone_of=unit_comp)
             cnx.commit()
-            transfer.cw_clear_relation_cache('seda_binary_data_object', 'object')
             imported_bdo, = [x for x in transfer.binary_data_objects if x.eid != bdo.eid]
             self.assertFormatEqual(imported_bdo,
                                    ['application/msword', 'application/pdf'],