web/test/unittest_views_basecontrollers.py
branchstable
changeset 6796 e70ca9abfc51
parent 6412 370357e68837
child 6875 a166b51d13f8
--- a/web/test/unittest_views_basecontrollers.py	Fri Jan 07 18:51:50 2011 +0100
+++ b/web/test/unittest_views_basecontrollers.py	Mon Jan 10 12:28:09 2011 +0100
@@ -47,8 +47,9 @@
     def test_noparam_edit(self):
         """check behaviour of this controller without any form parameter
         """
-        ex = self.assertRaises(ValidationError, self.ctrl_publish, self.request())
-        self.assertEqual(ex.errors, {None: u'no selected entities'})
+        with self.assertRaises(ValidationError) as cm:
+            self.ctrl_publish(self.request())
+        self.assertEqual(cm.exception.errors, {None: u'no selected entities'})
 
     def test_validation_unique(self):
         """test creation of two linked entities
@@ -61,8 +62,9 @@
                     'upassword-subject:X': u'toto',
                     'upassword-subject-confirm:X': u'toto',
                     }
-        ex = self.assertRaises(ValidationError, self.ctrl_publish, req)
-        self.assertEqual(ex.errors, {'login-subject': 'the value "admin" is already used, use another one'})
+        with self.assertRaises(ValidationError) as cm:
+            self.ctrl_publish(req)
+        self.assertEqual(cm.exception.errors, {'login-subject': 'the value "admin" is already used, use another one'})
 
     def test_user_editing_itself(self):
         """checking that a manager user can edit itself
@@ -205,8 +207,9 @@
                     'login-subject:X': u'toto',
                     'upassword-subject:X': u'toto',
                     }
-        ex = self.assertRaises(ValidationError, self.ctrl_publish, req)
-        self.assertEqual(ex.errors, {'upassword-subject': u'password and confirmation don\'t match'})
+        with self.assertRaises(ValidationError) as cm:
+            self.ctrl_publish(req)
+        self.assertEqual(cm.exception.errors, {'upassword-subject': u'password and confirmation don\'t match'})
         req = self.request()
         req.form = {'__cloned_eid:X': u(user.eid),
                     'eid': 'X', '__type:X': 'CWUser',
@@ -215,8 +218,9 @@
                     'upassword-subject:X': u'toto',
                     'upassword-subject-confirm:X': u'tutu',
                     }
-        ex = self.assertRaises(ValidationError, self.ctrl_publish, req)
-        self.assertEqual(ex.errors, {'upassword-subject': u'password and confirmation don\'t match'})
+        with self.assertRaises(ValidationError) as cm:
+            self.ctrl_publish(req)
+        self.assertEqual(cm.exception.errors, {'upassword-subject': u'password and confirmation don\'t match'})
 
 
     def test_interval_bound_constraint_success(self):
@@ -230,8 +234,9 @@
                     'amount-subject:X': u'-10',
                     'described_by_test-subject:X': u(feid),
                 }
-        ex = self.assertRaises(ValidationError, self.ctrl_publish, req)
-        self.assertEqual(ex.errors, {'amount-subject': 'value must be >= 0'})
+        with self.assertRaises(ValidationError) as cm:
+            self.ctrl_publish(req)
+        self.assertEqual(cm.exception.errors, {'amount-subject': 'value must be >= 0'})
         req = self.request(rollbackfirst=True)
         req.form = {'eid': ['X'],
                     '__type:X': 'Salesterm',
@@ -239,8 +244,9 @@
                     'amount-subject:X': u'110',
                     'described_by_test-subject:X': u(feid),
                     }
-        ex = self.assertRaises(ValidationError, self.ctrl_publish, req)
-        self.assertEqual(ex.errors, {'amount-subject': 'value must be <= 100'})
+        with self.assertRaises(ValidationError) as cm:
+            self.ctrl_publish(req)
+        self.assertEqual(cm.exception.errors, {'amount-subject': 'value must be <= 100'})
         req = self.request(rollbackfirst=True)
         req.form = {'eid': ['X'],
                     '__type:X': 'Salesterm',
@@ -421,8 +427,9 @@
                     'alias-subject:Y': u'',
                     'use_email-object:Y': 'X',
                     }
-        ex = self.assertRaises(ValidationError, self.ctrl_publish, req)
-        self.assertEqual(ex.errors, {'address-subject': u'required field'})
+        with self.assertRaises(ValidationError) as cm:
+            self.ctrl_publish(req)
+        self.assertEqual(cm.exception.errors, {'address-subject': u'required field'})
 
     def test_nonregr_copy(self):
         user = self.user()