entities/test/unittest_wfobjs.py
changeset 10280 2cdab5e33542
parent 10092 f0363da0b5a0
child 10353 d9a1e7939ee6
equal deleted inserted replaced
10279:d7479a5ac553 10280:2cdab5e33542
    50             wf = add_wf(shell, 'Company')
    50             wf = add_wf(shell, 'Company')
    51             wf.add_state(u'foo', initial=True)
    51             wf.add_state(u'foo', initial=True)
    52             shell.commit()
    52             shell.commit()
    53             with self.assertRaises(ValidationError) as cm:
    53             with self.assertRaises(ValidationError) as cm:
    54                 wf.add_state(u'foo')
    54                 wf.add_state(u'foo')
    55             self.assertEqual({'name': u'name is part of violated unicity constraint',
    55             self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
    56                               'state_of': u'state_of is part of violated unicity constraint',
    56                               'state_of': u'%(KEY-rtype)s is part of violated unicity constraint',
    57                               'unicity constraint': u'some relations violate a unicity constraint'},
    57                               '': u'some relations violate a unicity constraint'},
    58                              cm.exception.errors)
    58                              cm.exception.errors)
    59             shell.rollback()
    59             shell.rollback()
    60             # no pb if not in the same workflow
    60             # no pb if not in the same workflow
    61             wf2 = add_wf(shell, 'Company')
    61             wf2 = add_wf(shell, 'Company')
    62             foo = wf2.add_state(u'foo', initial=True)
    62             foo = wf2.add_state(u'foo', initial=True)
    65             bar = wf.add_state(u'bar')
    65             bar = wf.add_state(u'bar')
    66             shell.commit()
    66             shell.commit()
    67             with self.assertRaises(ValidationError) as cm:
    67             with self.assertRaises(ValidationError) as cm:
    68                 bar.cw_set(name=u'foo')
    68                 bar.cw_set(name=u'foo')
    69             shell.rollback()
    69             shell.rollback()
    70             self.assertEqual({'name': u'name is part of violated unicity constraint',
    70             self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
    71                               'state_of': u'state_of is part of violated unicity constraint',
    71                               'state_of': u'%(KEY-rtype)s is part of violated unicity constraint',
    72                               'unicity constraint': u'some relations violate a unicity constraint'},
    72                               '': u'some relations violate a unicity constraint'},
    73                              cm.exception.errors)
    73                              cm.exception.errors)
    74 
    74 
    75     def test_duplicated_transition(self):
    75     def test_duplicated_transition(self):
    76         with self.admin_access.shell() as shell:
    76         with self.admin_access.shell() as shell:
    77             wf = add_wf(shell, 'Company')
    77             wf = add_wf(shell, 'Company')
    78             foo = wf.add_state(u'foo', initial=True)
    78             foo = wf.add_state(u'foo', initial=True)
    79             bar = wf.add_state(u'bar')
    79             bar = wf.add_state(u'bar')
    80             wf.add_transition(u'baz', (foo,), bar, ('managers',))
    80             wf.add_transition(u'baz', (foo,), bar, ('managers',))
    81             with self.assertRaises(ValidationError) as cm:
    81             with self.assertRaises(ValidationError) as cm:
    82                 wf.add_transition(u'baz', (bar,), foo)
    82                 wf.add_transition(u'baz', (bar,), foo)
    83             self.assertEqual({'name': u'name is part of violated unicity constraint',
    83             self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
    84                               'transition_of': u'transition_of is part of violated unicity constraint',
    84                               'transition_of': u'%(KEY-rtype)s is part of violated unicity constraint',
    85                               'unicity constraint': u'some relations violate a unicity constraint'},
    85                               '': u'some relations violate a unicity constraint'},
    86                              cm.exception.errors)
    86                              cm.exception.errors)
    87             shell.rollback()
    87             shell.rollback()
    88             # no pb if not in the same workflow
    88             # no pb if not in the same workflow
    89             wf2 = add_wf(shell, 'Company')
    89             wf2 = add_wf(shell, 'Company')
    90             foo = wf.add_state(u'foo', initial=True)
    90             foo = wf.add_state(u'foo', initial=True)
    95             biz = wf.add_transition(u'biz', (bar,), foo)
    95             biz = wf.add_transition(u'biz', (bar,), foo)
    96             shell.commit()
    96             shell.commit()
    97             with self.assertRaises(ValidationError) as cm:
    97             with self.assertRaises(ValidationError) as cm:
    98                 biz.cw_set(name=u'baz')
    98                 biz.cw_set(name=u'baz')
    99             shell.rollback()
    99             shell.rollback()
   100             self.assertEqual({'name': u'name is part of violated unicity constraint',
   100             self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
   101                               'transition_of': u'transition_of is part of violated unicity constraint',
   101                               'transition_of': u'%(KEY-rtype)s is part of violated unicity constraint',
   102                               'unicity constraint': u'some relations violate a unicity constraint'},
   102                               '': u'some relations violate a unicity constraint'},
   103                              cm.exception.errors)
   103                              cm.exception.errors)
   104 
   104 
   105 
   105 
   106 class WorkflowTC(CubicWebTC):
   106 class WorkflowTC(CubicWebTC):
   107 
   107