[PATCH 1 of 2 seda] [test] Generalize method to test on which entities some diagnosis error occurs

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Dec 6 09:57:55 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1512548869 -3600
#      Wed Dec 06 09:27:49 2017 +0100
# Node ID 97d51edffffe26ff0468c4d062b9de705d8bcaf3
# Parent  d4a8d79500071e5486fb04f44d81c27afc7bb9a2
[test] Generalize method to test on which entities some diagnosis error occurs

diff --git a/test/test_diag.py b/test/test_diag.py
--- a/test/test_diag.py
+++ b/test/test_diag.py
@@ -156,20 +156,20 @@ class CompatAnalyzerTC(CubicWebTC):
             cnx.commit()
             unit2.cw_set(user_cardinality=u'1..n')
             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()
             self.assertIsRNGAmbiguous(transfer, False)
 
             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()
             self.assertIsRNGAmbiguous(transfer, False)
 
@@ -182,12 +182,12 @@ class CompatAnalyzerTC(CubicWebTC):
                                          seda_binary_data_object=transfer)
             bdo = testutils.create_data_object(unit_alt_seq, user_cardinality=u'1..n',
                                                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)
 
             # test data objects cardinality is considered globally to the profil
@@ -195,22 +195,22 @@ class CompatAnalyzerTC(CubicWebTC):
             unit2, unit2_alt, unit2_alt_seq = testutils.create_archive_unit(transfer)
             bdo = testutils.create_data_object(unit2_alt_seq, user_cardinality=u'0..n',
                                                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)
 
             # though adding a data object with card != 1 to another archive unit
             # **on a simplified profile** is fine
             transfer.cw_set(simplified_profile=True)
             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):
         with self.admin_access.cnx() as cnx:
             transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
@@ -220,17 +220,17 @@ class CompatAnalyzerTC(CubicWebTC):
                               user_cardinality=u'1..n')
             cnx.create_entity('SEDAKeyword', seda_keyword=unit_alt_seq,
                               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))
 
     def assertIsRNGAmbiguous(self, transfer, ambiguous):


More information about the saem-devel mailing list