Florent Cayré avatar Florent Cayré committed 8fff4f3

refactor tests a bit

Comments (0)

Files changed (3)

Empty file added.

test/unittest_schema.py

 from cubicweb import ValidationError, Unauthorized
 from cubicweb.devtools.testlib import CubicWebTC
 
+from cubes.processing.test.utils import ProcessingTCMixin
 
-class ProcessingSchemaTCMixin(object):
 
-    def setup_database(self):
-        super(ProcessingSchemaTCMixin, self).setup_database()
-        ce = self.request().create_entity
-        self.code = ce('ComputationCode', name=u'code')
-        self.exe = ce('Executable', executable_of=self.code)
-        self.commit()
-
-    def assertErrorMsg(self, ctm, expected):
-        if not str(ctm.exception).endswith(expected):
-           self.fail('did not get error %r but %s' % (expected, ctm.exception))
-
-
-class ParameterDefinitionSchemaTC(ProcessingSchemaTCMixin, CubicWebTC):
+class ParameterDefinitionSchemaTC(ProcessingTCMixin, CubicWebTC):
 
     def test_pdef_name_validity(self):
         'check parameter definition name restrictions'
         with self.assertRaises(ValidationError) as ctm:
             p1 = ce('ParameterDefinition', name=u'p 1', value_type=u'Float',
                     parameter_of=self.exe)
-        self.assertErrorMsg(ctm, ("doesn't match the '^[a-zA-Z0-9_]+$' "
-                                  "regular expression"))
+        self.assertExcMsg(ctm, ("doesn't match the '^[a-zA-Z0-9_]+$' "
+                                "regular expression"))
 
     def test_exe_unused(self):
         'parameter definition cannot be added to an already used executable'
             p = ce('ParameterDefinition', name=u'p',  value_type=u'Float',
                    parameter_of=self.exe)
             self.commit()
-        self.assertErrorMsg(ctm, ('executable is already used in a Run'))
+        self.assertExcMsg(ctm, ('executable is already used in a Run'))
 
     def test_pdef_unique(self):
         'same parameter definition name for same executable is invalid'
             ce('ParameterDefinition', name=p1.name,
                value_type=u'Float', parameter_of=p1.parameter_of[0])
             self.commit()
-        self.assertErrorMsg(ctm, 'parameter name is already used')
+        self.assertExcMsg(ctm, 'parameter name is already used')
 
 
-class ObjectiveDefinitionSchemaTC(ProcessingSchemaTCMixin, CubicWebTC):
+class ObjectiveDefinitionSchemaTC(ProcessingTCMixin, CubicWebTC):
 
     def test_odef_name_validity(self):
         'check objective definition name restrictions'
         with self.assertRaises(ValidationError) as ctm:
             o1 = ce('ObjectiveDefinition', name=u'o 1', value_type=u'Float',
                     objective_of=self.exe)
-        self.assertErrorMsg(ctm, ("doesn't match the '^[a-zA-Z0-9_]+$' "
-                                  "regular expression"))
+        self.assertExcMsg(ctm, ("doesn't match the '^[a-zA-Z0-9_]+$' "
+                                "regular expression"))
 
     def test_exe_unused(self):
         'objective definition cannot be added to an already used executable'
             p = ce('ObjectiveDefinition', name=u'p', value_type=u'Float',
                    objective_of=self.exe)
             self.commit()
-        self.assertErrorMsg(ctm, ('executable is already used in a Run'))
+        self.assertExcMsg(ctm, ('executable is already used in a Run'))
 
     def test_odef_unique(self):
         'same objective definition name for same executable is invalid'
             ce('ObjectiveDefinition', name=o1.name, value_type=u'Float',
                objective_of=o1.objective_of[0])
             self.commit()
-        self.assertErrorMsg(ctm, 'objective name is already used')
+        self.assertExcMsg(ctm, 'objective name is already used')
 
 
-class ParameterValueSchemaTC(ProcessingSchemaTCMixin, CubicWebTC):
+class ParameterValueSchemaTC(ProcessingTCMixin, CubicWebTC):
 
     def setup_database(self):
         super(ParameterValueSchemaTC, self).setup_database()
             self.commit()
 
 
-class ParameterValueChainingTC(ProcessingSchemaTCMixin, CubicWebTC):
+class ParameterValueChainingTC(ProcessingTCMixin, CubicWebTC):
 
     def setup_database(self):
         super(ParameterValueChainingTC, self).setup_database()
                      reverse_param_values=run1, from_run=run0, from_obj=self.obj0_f)
         self.commit()
 
-class RunSchemaTC(ProcessingSchemaTCMixin, CubicWebTC):
+class RunSchemaTC(ProcessingTCMixin, CubicWebTC):
 
     def test_param_values_pdef_exists_ok(self):
         'can add parameter if it corresponds to a param def of the executable'
                reverse_param_values=run)
             self.commit()
         self.rollback()
-        self.assertErrorMsg(ctm, 'cannot find this parameter for this executable')
+        self.assertExcMsg(ctm, 'cannot find this parameter for this executable')
 
     def test_executable_constraint(self):
         '''cannot link run to executable with param defs without defining
             ce('Run', executable=self.exe)
             self.commit()
         self.rollback()
-        self.assertErrorMsg(ctm, 'missing parameter values')
+        self.assertExcMsg(ctm, 'missing parameter values')
 
     def test_param_values_unique(self):
         'cannot add 2 param values for the same definition on same run'
             ce('ParameterValueFloat', param_def=p, value=1.,
                reverse_param_values=run)
             self.commit()
-        self.assertErrorMsg(ctm, 'parameter has several values')
+        self.assertExcMsg(ctm, 'parameter has several values')
 
     def test_obj_values_odef_exists_ok(self):
         'can add objective if it corresponds to a obj def of the executable'
                reverse_obj_values=run)
             self.commit()
         self.rollback()
-        self.assertErrorMsg(ctm, 'cannot find this objective for this executable')
+        self.assertExcMsg(ctm, 'cannot find this objective for this executable')
 
     def test_obj_values_unique(self):
         'cannot add 2 obj values for the same definition on same run'
             ce('ObjectiveValueFloat', obj_def=p, value=1.,
                reverse_obj_values=run)
             self.commit()
-        self.assertErrorMsg(ctm, 'objective has several values')
+        self.assertExcMsg(ctm, 'objective has several values')
+# -*- coding: utf-8 -*-
+# copyright 2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr -- mailto:contact@logilab.fr
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+class ProcessingTCMixin(object):
+
+    def setup_database(self):
+        super(ProcessingTCMixin, self).setup_database()
+        ce = self.request().create_entity
+        self.code = ce('ComputationCode', name=u'code')
+        self.exe = ce('Executable', executable_of=self.code)
+        self.commit()
+
+    def assertExcMsg(self, ctm, expected):
+        if not str(ctm.exception).endswith(expected):
+           self.fail('did not get error %r but %s' % (expected, ctm.exception))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.