493 # self.execute('INSERT CWUser X: X login "badaboum", X upassword %(pwd)s, ' |
493 # self.execute('INSERT CWUser X: X login "badaboum", X upassword %(pwd)s, ' |
494 # 'X in_state S, X in_group G WHERE S name "deactivated", G name "users"', {'pwd': 'oops'}) |
494 # 'X in_state S, X in_group G WHERE S name "deactivated", G name "users"', {'pwd': 'oops'}) |
495 # self.commit() |
495 # self.commit() |
496 |
496 |
497 # test that the workflow is correctly enforced |
497 # test that the workflow is correctly enforced |
|
498 |
|
499 def _cleanup_msg(self, msg): |
|
500 """remove the variable part of one specific error message""" |
|
501 lmsg = msg.split() |
|
502 lmsg.pop(1) |
|
503 lmsg.pop() |
|
504 return ' '.join(lmsg) |
|
505 |
498 def test_transition_checking1(self): |
506 def test_transition_checking1(self): |
499 cnx = self.login('stduser') |
507 cnx = self.login('stduser') |
500 user = cnx.user(self.current_session()) |
508 user = cnx.user(self.current_session()) |
501 ex = self.assertRaises(ValidationError, |
509 ex = self.assertRaises(ValidationError, |
502 user.fire_transition, 'activate') |
510 user.fire_transition, 'activate') |
503 self.assertEquals(ex.errors, {'by_transition': u"transition isn't allowed"}) |
511 self.assertEquals(self._cleanup_msg(ex.errors['by_transition']), |
|
512 u"transition isn't allowed from") |
504 cnx.close() |
513 cnx.close() |
505 |
514 |
506 def test_transition_checking2(self): |
515 def test_transition_checking2(self): |
507 cnx = self.login('stduser') |
516 cnx = self.login('stduser') |
508 user = cnx.user(self.current_session()) |
517 user = cnx.user(self.current_session()) |
509 assert user.state == 'activated' |
518 assert user.state == 'activated' |
510 ex = self.assertRaises(ValidationError, |
519 ex = self.assertRaises(ValidationError, |
511 user.fire_transition, 'dummy') |
520 user.fire_transition, 'dummy') |
512 self.assertEquals(ex.errors, {'by_transition': u"transition isn't allowed"}) |
521 self.assertEquals(self._cleanup_msg(ex.errors['by_transition']), |
|
522 u"transition isn't allowed from") |
513 cnx.close() |
523 cnx.close() |
514 |
524 |
515 def test_transition_checking3(self): |
525 def test_transition_checking3(self): |
516 cnx = self.login('stduser') |
526 cnx = self.login('stduser') |
517 session = self.current_session() |
527 session = self.current_session() |
519 user.fire_transition('deactivate') |
529 user.fire_transition('deactivate') |
520 cnx.commit() |
530 cnx.commit() |
521 session.set_pool() |
531 session.set_pool() |
522 ex = self.assertRaises(ValidationError, |
532 ex = self.assertRaises(ValidationError, |
523 user.fire_transition, 'deactivate') |
533 user.fire_transition, 'deactivate') |
524 self.assertEquals(ex.errors, {'by_transition': u"transition isn't allowed"}) |
534 self.assertEquals(self._cleanup_msg(ex.errors['by_transition']), |
|
535 u"transition isn't allowed from") |
525 # get back now |
536 # get back now |
526 user.fire_transition('activate') |
537 user.fire_transition('activate') |
527 cnx.commit() |
538 cnx.commit() |
528 cnx.close() |
539 cnx.close() |
529 |
540 |