[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
--- a/devtools/testlib.py Thu Oct 07 19:02:00 2010 +0200
+++ b/devtools/testlib.py Fri Oct 08 07:43:38 2010 +0200
@@ -533,9 +533,11 @@
return publisher
requestcls = fake.FakeRequest
- def request(self, *args, **kwargs):
+ def request(self, rollbackfirst=False, **kwargs):
"""return a web ui request"""
req = self.requestcls(self.vreg, form=kwargs)
+ if rollbackfirst:
+ self.websession.cnx.rollback()
req.set_session(self.websession)
return req
--- a/entities/test/unittest_wfobjs.py Thu Oct 07 19:02:00 2010 +0200
+++ b/entities/test/unittest_wfobjs.py Fri Oct 08 07:43:38 2010 +0200
@@ -618,6 +618,8 @@
iworkflowable.fire_transition, 'deactivate')
self.assertEqual(self._cleanup_msg(ex.errors['by_transition-subject']),
u"transition isn't allowed from")
+ cnx.rollback()
+ session.set_pool()
# get back now
iworkflowable.fire_transition('activate')
cnx.commit()
--- a/hooks/test/unittest_syncschema.py Thu Oct 07 19:02:00 2010 +0200
+++ b/hooks/test/unittest_syncschema.py Fri Oct 08 07:43:38 2010 +0200
@@ -258,6 +258,7 @@
self.commit()
# should not be able anymore to add cwuser without surname
self.assertRaises(ValidationError, self.create_user, "toto")
+ self.rollback()
self.execute('SET DEF cardinality "?1" '
'WHERE DEF relation_type RT, DEF from_entity E,'
'RT name "surname", E name "CWUser"')
--- a/server/test/unittest_security.py Thu Oct 07 19:02:00 2010 +0200
+++ b/server/test/unittest_security.py Fri Oct 08 07:43:38 2010 +0200
@@ -22,7 +22,7 @@
from logilab.common.testlib import unittest_main, TestCase
from cubicweb.devtools.testlib import CubicWebTC
-from cubicweb import Unauthorized, ValidationError
+from cubicweb import Unauthorized, ValidationError, QueryError
from cubicweb.server.querier import check_read_access
class BaseSecurityTC(CubicWebTC):
@@ -189,6 +189,8 @@
cnx.commit()
# to actually get Unauthorized exception, try to delete an entity we can read
self.assertRaises(Unauthorized, cu.execute, "DELETE Societe S")
+ self.assertRaises(QueryError, cnx.commit) # can't commit anymore
+ cnx.rollback() # required after Unauthorized
cu.execute("INSERT Affaire X: X sujet 'pascool'")
cu.execute("INSERT Societe X: X nom 'chouette'")
cu.execute("SET A concerne S WHERE A sujet 'pascool', S nom 'chouette'")
@@ -216,6 +218,8 @@
self.assertRaises(Unauthorized, ent.cw_check_perm, 'update')
self.assertRaises(Unauthorized,
cu.execute, "SET P travaille S WHERE P is Personne, S is Societe")
+ self.assertRaises(QueryError, cnx.commit) # can't commit anymore
+ cnx.rollback()
# test nothing has actually been inserted:
self.assertEqual(cu.execute('Any P,S WHERE P travaille S,P is Personne, S is Societe').rowcount, 0)
cu.execute("INSERT Societe X: X nom 'chouette'")
@@ -239,6 +243,8 @@
cnx = self.login('iaminusersgrouponly')
cu = cnx.cursor()
self.assertRaises(Unauthorized, cu.execute, "DELETE A concerne S")
+ self.assertRaises(QueryError, cnx.commit) # can't commit anymore
+ cnx.rollback() # required after Unauthorized
cu.execute("INSERT Societe X: X nom 'chouette'")
cu.execute("SET A concerne S WHERE A is Affaire, S nom 'chouette'")
cnx.commit()
--- a/web/test/unittest_views_basecontrollers.py Thu Oct 07 19:02:00 2010 +0200
+++ b/web/test/unittest_views_basecontrollers.py Fri Oct 08 07:43:38 2010 +0200
@@ -223,7 +223,7 @@
feid = self.execute('INSERT File X: X data_name "toto.txt", X data %(data)s',
{'data': Binary('yo')})[0][0]
self.commit()
- req = self.request()
+ req = self.request(rollbackfirst=True)
req.form = {'eid': ['X'],
'__type:X': 'Salesterm',
'_cw_edited_fields:X': 'amount-subject,described_by_test-subject',
@@ -232,7 +232,7 @@
}
ex = self.assertRaises(ValidationError, self.ctrl_publish, req)
self.assertEqual(ex.errors, {'amount-subject': 'value must be >= 0'})
- req = self.request()
+ req = self.request(rollbackfirst=True)
req.form = {'eid': ['X'],
'__type:X': 'Salesterm',
'_cw_edited_fields:X': 'amount-subject,described_by_test-subject',
@@ -241,7 +241,7 @@
}
ex = self.assertRaises(ValidationError, self.ctrl_publish, req)
self.assertEqual(ex.errors, {'amount-subject': 'value must be <= 100'})
- req = self.request()
+ req = self.request(rollbackfirst=True)
req.form = {'eid': ['X'],
'__type:X': 'Salesterm',
'_cw_edited_fields:X': 'amount-subject,described_by_test-subject',