414 iworkflowable.fire_transition(trans) |
414 iworkflowable.fire_transition(trans) |
415 req.cnx.commit() |
415 req.cnx.commit() |
416 group.cw_clear_all_caches() |
416 group.cw_clear_all_caches() |
417 self.assertEqual(iworkflowable.state, nextstate) |
417 self.assertEqual(iworkflowable.state, nextstate) |
418 |
418 |
|
419 def test_replace_state(self): |
|
420 with self.admin_access.shell() as shell: |
|
421 wf = add_wf(shell, 'CWGroup', name='groupwf', default=True) |
|
422 s_new = wf.add_state('new', initial=True) |
|
423 s_state1 = wf.add_state('state1') |
|
424 wf.add_transition('tr', (s_new,), s_state1) |
|
425 shell.commit() |
|
426 |
|
427 with self.admin_access.repo_cnx() as cnx: |
|
428 group = cnx.create_entity('CWGroup', name=u'grp1') |
|
429 cnx.commit() |
|
430 |
|
431 iwf = group.cw_adapt_to('IWorkflowable') |
|
432 iwf.fire_transition('tr') |
|
433 cnx.commit() |
|
434 group.cw_clear_all_caches() |
|
435 |
|
436 wf = cnx.entity_from_eid(wf.eid) |
|
437 wf.add_state('state2') |
|
438 with cnx.security_enabled(write=False): |
|
439 wf.replace_state('state1', 'state2') |
|
440 cnx.commit() |
|
441 |
|
442 self.assertEqual(iwf.state, 'state2') |
|
443 self.assertEqual(iwf.latest_trinfo().to_state[0].name, 'state2') |
|
444 |
419 |
445 |
420 class CustomWorkflowTC(CubicWebTC): |
446 class CustomWorkflowTC(CubicWebTC): |
421 |
447 |
422 def setup_database(self): |
448 def setup_database(self): |
423 with self.admin_access.repo_cnx() as cnx: |
449 with self.admin_access.repo_cnx() as cnx: |