nicer error message on rql constraints stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 03 Dec 2009 09:57:55 +0100
branchstable
changeset 3983 e2dc12753436
parent 3982 ac2a54a6f36f
child 3984 54b5c9873ccb
nicer error message on rql constraints
entities/test/unittest_wfobjs.py
schemas/workflow.py
--- a/entities/test/unittest_wfobjs.py	Thu Dec 03 09:57:32 2009 +0100
+++ b/entities/test/unittest_wfobjs.py	Thu Dec 03 09:57:55 2009 +0100
@@ -45,6 +45,7 @@
         # gnark gnark
         bar = wf.add_state(u'bar')
         self.commit()
+        print '*'*80
         bar.set_attributes(name=u'foo')
         ex = self.assertRaises(ValidationError, self.commit)
         self.assertEquals(ex.errors, {'name': 'workflow already have a state of that name'})
@@ -395,7 +396,7 @@
         self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s',
                      {'wf': wf.eid, 'x': self.member.eid})
         ex = self.assertRaises(ValidationError, self.commit)
-        self.assertEquals(ex.errors, {'custom_workflow': 'constraint S is ET, O workflow_of ET failed'})
+        self.assertEquals(ex.errors, {'custom_workflow': 'workflow isn\'t a workflow for this type'})
 
     def test_del_custom_wf(self):
         """member in some state shared by the new workflow, nothing has to be
--- a/schemas/workflow.py	Thu Dec 03 09:57:32 2009 +0100
+++ b/schemas/workflow.py	Thu Dec 03 09:57:55 2009 +0100
@@ -27,7 +27,8 @@
                                   constraints=[RQLConstraint('O final FALSE')])
 
     initial_state = SubjectRelation('State', cardinality='?*',
-                                   constraints=[RQLConstraint('O state_of S')],
+                                   constraints=[RQLConstraint('O state_of S',
+                                                              msg=_('state doesn\'t belong to this workflow'))],
                                    description=_('initial state for this workflow'))
 
 
@@ -38,7 +39,8 @@
     subject = 'CWEType'
     object = 'Workflow'
     cardinality = '?*'
-    constraints = [RQLConstraint('S final FALSE, O workflow_of S')]
+    constraints = [RQLConstraint('S final FALSE, O workflow_of S',
+                                 msg=_('workflow isn\'t a workflow of this type'))]
 
 
 class State(EntityType):
@@ -57,7 +59,8 @@
     # XXX should be on BaseTransition w/ AND/OR selectors when we will
     # implements #345274
     allowed_transition = SubjectRelation('BaseTransition', cardinality='**',
-                                         constraints=[RQLConstraint('S state_of WF, O transition_of WF')],
+                                         constraints=[RQLConstraint('S state_of WF, O transition_of WF',
+                                                                    msg=_('state and transition don\'t belong the the same workflow'))],
                                          description=_('allowed transitions from this state'))
     state_of = SubjectRelation('Workflow', cardinality='1*', composite='object',
                                description=_('workflow to which this state belongs'),
@@ -89,7 +92,7 @@
     transition_of = SubjectRelation('Workflow', cardinality='1*', composite='object',
                                     description=_('workflow to which this transition belongs'),
                                     constraints=[RQLUniqueConstraint('S name N, Y transition_of O, Y name N', 'Y',
-                                                                     _('workflow already have a state of that name'))])
+                                                                     _('workflow already have a transition of that name'))])
 
 
 class Transition(BaseTransition):
@@ -100,7 +103,8 @@
 
     destination_state = SubjectRelation(
         'State', cardinality='1*',
-        constraints=[RQLConstraint('S transition_of WF, O state_of WF')],
+        constraints=[RQLConstraint('S transition_of WF, O state_of WF',
+                                   msg=_('state and transition don\'t belong the the same workflow'))],
         description=_('destination state for this transition'))
 
 
@@ -109,7 +113,9 @@
     __specializes_schema__ = True
 
     subworkflow = SubjectRelation('Workflow', cardinality='1*',
-                                  constraints=[RQLConstraint('S transition_of WF, WF workflow_of ET, O workflow_of ET')])
+                                  constraints=[RQLConstraint('S transition_of WF, WF workflow_of ET, O workflow_of ET',
+                                                             msg=_('subworkflow isn\'t a workflow for the same types as the transition\'s workflow'))]
+                                  )
     # XXX use exit_of and inline it
     subworkflow_exit = SubjectRelation('SubWorkflowExitPoint', cardinality='*1',
                                        composite='subject')
@@ -119,11 +125,13 @@
     """define how we get out from a sub-workflow"""
     subworkflow_state = SubjectRelation(
         'State', cardinality='1*',
-        constraints=[RQLConstraint('T subworkflow_exit S, T subworkflow WF, O state_of WF')],
+        constraints=[RQLConstraint('T subworkflow_exit S, T subworkflow WF, O state_of WF',
+                                   msg=_('exit state must a subworkflow state'))],
         description=_('subworkflow state'))
     destination_state = SubjectRelation(
         'State', cardinality='?*',
-        constraints=[RQLConstraint('T subworkflow_exit S, T transition_of WF, O state_of WF')],
+        constraints=[RQLConstraint('T subworkflow_exit S, T transition_of WF, O state_of WF',
+                                   msg=_('destination state must be in the same workflow as our parent transition'))],
         description=_('destination state. No destination state means that transition '
                       'should go back to the state from which we\'ve entered the '
                       'subworkflow.'))
@@ -218,7 +226,8 @@
     permissions = META_RTYPE_PERMS
 
     cardinality = '?*'
-    constraints = [RQLConstraint('S is ET, O workflow_of ET')]
+    constraints = [RQLConstraint('S is ET, O workflow_of ET',
+                                 msg=_('workflow isn\'t a workflow for this type'))]
     object = 'Workflow'
 
 
@@ -247,5 +256,6 @@
     inlined = False
 
     cardinality = '1*'
-    constraints = [RQLConstraint('S is ET, O state_of WF, WF workflow_of ET')]
+    constraints = [RQLConstraint('S is ET, O state_of WF, WF workflow_of ET',
+                                 msg=_('state doesn\'t apply to this entity\'s type'))]
     object = 'State'