[test] Generalize method to test on which entities some diagnosis error occurs
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 06 Dec 2017 09:27:49 +0100
changeset 2885 97d51edffffe
parent 2884 d4a8d7950007
child 2886 09d4339eaab2
[test] Generalize method to test on which entities some diagnosis error occurs
test/test_diag.py
--- a/test/test_diag.py	Wed Nov 15 08:24:37 2017 +0100
+++ b/test/test_diag.py	Wed Dec 06 09:27:49 2017 +0100
@@ -158,7 +158,7 @@
             cnx.commit()
 
             self.assertIsRNGAmbiguous(transfer, True)
-            self.assertRNGAmbiguousDiagnostic(doctor, [(transfer, 'seda_archive_units_tab')])
+            self.assertErrorOn(doctor, 'rng_ambiguity', [(transfer, 'seda_archive_units_tab')])
 
             unit2.cw_set(user_cardinality=u'1')
             cnx.commit()
@@ -167,7 +167,7 @@
             unit3 = testutils.create_archive_unit(transfer, user_cardinality=u'0..1')[0]
             cnx.commit()
             self.assertIsRNGAmbiguous(transfer, True)
-            self.assertRNGAmbiguousDiagnostic(doctor, [(transfer, 'seda_archive_units_tab')])
+            self.assertErrorOn(doctor, 'rng_ambiguity', [(transfer, 'seda_archive_units_tab')])
 
             unit3.cw_delete()
             cnx.commit()
@@ -184,8 +184,8 @@
                                                seda_binary_data_object=transfer)
             cnx.commit()
             self.assertIsRNGAmbiguous(transfer, True)
-            self.assertRNGAmbiguousDiagnostic(doctor, [(unit, 'seda_data_objects_tab'),
-                                                       (transfer, 'seda_data_objects_tab')])
+            self.assertErrorOn(doctor, 'rng_ambiguity', [(unit, 'seda_data_objects_tab'),
+                                                         (transfer, 'seda_data_objects_tab')])
             _delete_data_object(bdo)
             cnx.commit()
             self.assertIsRNGAmbiguous(transfer, False)
@@ -197,7 +197,7 @@
                                                seda_binary_data_object=transfer)
             cnx.commit()
             self.assertIsRNGAmbiguous(transfer, True)
-            self.assertRNGAmbiguousDiagnostic(doctor, [(transfer, 'seda_data_objects_tab')])
+            self.assertErrorOn(doctor, 'rng_ambiguity', [(transfer, 'seda_data_objects_tab')])
             _delete_data_object(bdo)
             cnx.commit()
             self.assertIsRNGAmbiguous(transfer, False)
@@ -208,7 +208,7 @@
             testutils.create_data_object(unit2_alt_seq, user_cardinality=u'0..n',
                                          seda_binary_data_object=transfer)
             cnx.commit()
-            self.assertRNGAmbiguousDiagnostic(doctor, [])
+            self.assertErrorOn(doctor, 'rng_ambiguity', [])
             self.assertIsRNGAmbiguous(transfer, False)
 
     def test_multiple_child_unhandled_cardinality_keyword(self):
@@ -222,13 +222,13 @@
                               user_cardinality=u'1..n')
             cnx.commit()
 
-            self.assertRNGAmbiguousDiagnostic(doctor, [(unit, 'seda_indexation_tab')])
+            self.assertErrorOn(doctor, 'rng_ambiguity', [(unit, 'seda_indexation_tab')])
 
-    def assertRNGAmbiguousDiagnostic(self, doctor, expected_errors):
+    def assertErrorOn(self, doctor, error_id, expected_errors):
         errors = set()
         for error in doctor.detect_problems():
             print('assert diag error', error.rule_id)
-            if error.rule_id == 'rng_ambiguity':
+            if error.rule_id == error_id:
                 errors.add((error.entity, error.tab_id))
 
         self.assertEqual(errors, set(expected_errors))