entities/test/unittest_wfobjs.py
changeset 4835 13b0b96d7982
parent 4644 021035b9a7ab
child 5030 5238d9a8dfee
equal deleted inserted replaced
4834:b718626a0e60 4835:13b0b96d7982
       
     1 from __future__ import with_statement
     1 from cubicweb.devtools.testlib import CubicWebTC
     2 from cubicweb.devtools.testlib import CubicWebTC
     2 from cubicweb import ValidationError
     3 from cubicweb import ValidationError
       
     4 from cubicweb.server.session import security_enabled
     3 
     5 
     4 def add_wf(self, etype, name=None, default=False):
     6 def add_wf(self, etype, name=None, default=False):
     5     if name is None:
     7     if name is None:
     6         name = etype
     8         name = etype
     7     wf = self.execute('INSERT Workflow X: X name %(n)s', {'n': unicode(name)}).get_entity(0, 0)
     9     wf = self.execute('INSERT Workflow X: X name %(n)s', {'n': unicode(name)}).get_entity(0, 0)
   124 
   126 
   125     def test_set_in_state_bad_wf(self):
   127     def test_set_in_state_bad_wf(self):
   126         wf = add_wf(self, 'CWUser')
   128         wf = add_wf(self, 'CWUser')
   127         s = wf.add_state(u'foo', initial=True)
   129         s = wf.add_state(u'foo', initial=True)
   128         self.commit()
   130         self.commit()
   129         ex = self.assertRaises(ValidationError, self.session.unsafe_execute,
   131         with security_enabled(self.session, write=False):
       
   132             ex = self.assertRaises(ValidationError, self.session.execute,
   130                                'SET X in_state S WHERE X eid %(x)s, S eid %(s)s',
   133                                'SET X in_state S WHERE X eid %(x)s, S eid %(s)s',
   131                                {'x': self.user().eid, 's': s.eid}, 'x')
   134                                {'x': self.user().eid, 's': s.eid}, 'x')
   132         self.assertEquals(ex.errors, {'in_state': "state doesn't belong to entity's workflow. "
   135             self.assertEquals(ex.errors, {'in_state': "state doesn't belong to entity's workflow. "
   133                                       "You may want to set a custom workflow for this entity first."})
   136                                       "You may want to set a custom workflow for this entity first."})
   134 
   137 
   135     def test_fire_transition(self):
   138     def test_fire_transition(self):
   136         user = self.user()
   139         user = self.user()
   137         user.fire_transition('deactivate', comment=u'deactivate user')
   140         user.fire_transition('deactivate', comment=u'deactivate user')
   503         self.execute('SET X require_group G '
   506         self.execute('SET X require_group G '
   504                      'WHERE G name "users", X transition_of WF, WF eid %(wf)s',
   507                      'WHERE G name "users", X transition_of WF, WF eid %(wf)s',
   505                      {'wf': self.wf.eid})
   508                      {'wf': self.wf.eid})
   506         self.commit()
   509         self.commit()
   507 
   510 
   508     # XXX currently, we've to rely on hooks to set initial state, or to use unsafe_execute
   511     # XXX currently, we've to rely on hooks to set initial state, or to use execute
   509     # def test_initial_state(self):
   512     # def test_initial_state(self):
   510     #     cnx = self.login('stduser')
   513     #     cnx = self.login('stduser')
   511     #     cu = cnx.cursor()
   514     #     cu = cnx.cursor()
   512     #     self.assertRaises(ValidationError, cu.execute,
   515     #     self.assertRaises(ValidationError, cu.execute,
   513     #                       'INSERT CWUser X: X login "badaboum", X upassword %(pwd)s, '
   516     #                       'INSERT CWUser X: X login "badaboum", X upassword %(pwd)s, '