From 5f8f5260c4403a438fba32735a689037fe982403 Mon Sep 17 00:00:00 2001 From: Torsten Werner Date: Mon, 24 Jan 2011 07:51:30 +0100 Subject: [PATCH] ValidatorTestCase: test before_update, too. Signed-off-by: Torsten Werner --- tests/dbtest_validation.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/dbtest_validation.py b/tests/dbtest_validation.py index 597097c9..32f47eb8 100755 --- a/tests/dbtest_validation.py +++ b/tests/dbtest_validation.py @@ -12,26 +12,22 @@ class ValidatorTestCase(DBDakTestCase): The ValidatorTestCase tests the validation mechanism. """ - def must_fail(self): - '''' - This function must fail with DBUpdateError because arch_string is not - set. It rolls back the transaction before re-raising the exception. - ''' - try: - architecture = Architecture() - self.session.add(architecture) - self.session.flush() - except: - self.session.rollback() - raise - def test_validation(self): 'tests validate()' - self.assertRaises(DBUpdateError, self.must_fail) + + # before_insert validation should fail + architecture = Architecture() + self.session.add(architecture) + self.assertRaises(DBUpdateError, self.session.flush) + self.session.rollback() # should not fail architecture = Architecture('i386') self.session.add(architecture) self.session.flush() + # before_update validation should fail + architecture.arch_string = '' + self.assertRaises(DBUpdateError, self.session.flush) + self.session.rollback() if __name__ == '__main__': unittest.main() -- 2.39.5