From: Torsten Werner <twerner@debian.org>
Date: Mon, 24 Jan 2011 06:51:30 +0000 (+0100)
Subject: ValidatorTestCase: test before_update, too.
X-Git-Tag: debian-r/squeeze~391^2~1^2
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5f8f5260c4403a438fba32735a689037fe982403;p=dak.git

ValidatorTestCase: test before_update, too.

Signed-off-by: Torsten Werner <twerner@debian.org>
---

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()