--- a/devtools/testlib.py Thu Oct 07 19:04:07 2010 +0200
+++ b/devtools/testlib.py Fri Oct 08 07:55:11 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:04:07 2010 +0200
+++ b/entities/test/unittest_wfobjs.py Fri Oct 08 07:55:11 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:04:07 2010 +0200
+++ b/hooks/test/unittest_syncschema.py Fri Oct 08 07:55:11 2010 +0200
@@ -15,6 +15,8 @@
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
+"""cubicweb.server.hooks.syncschema unit and functional tests"""
+
from logilab.common.testlib import TestCase, unittest_main
from cubicweb import ValidationError
@@ -258,6 +260,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:04:07 2010 +0200
+++ b/server/test/unittest_security.py Fri Oct 08 07:55:11 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/test/unittest_cwconfig.py Thu Oct 07 19:04:07 2010 +0200
+++ b/test/unittest_cwconfig.py Fri Oct 08 07:55:11 2010 +0200
@@ -98,8 +98,8 @@
def test_expand_cubes(self):
self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR]
self.config.adjust_sys_path()
- self.assertEqual(self.config.expand_cubes(('email', 'blog')),
- ['email', 'blog', 'file'])
+ self.assertEqual(self.config.expand_cubes(('email', 'comment')),
+ ['email', 'comment', 'file'])
def test_vregistry_path(self):
self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR]
@@ -113,7 +113,7 @@
def test_cubes_path(self):
# make sure we don't import the email cube, but the stdlib email package
import email
- self.assertNotEquals(dirname(email.__file__), self.config.CUBES_DIR)
+ self.assertNotEqual(dirname(email.__file__), self.config.CUBES_DIR)
self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR]
self.assertEqual(self.config.cubes_search_path(),
[CUSTOM_CUBES_DIR, self.config.CUBES_DIR])
--- a/web/test/unittest_views_basecontrollers.py Thu Oct 07 19:04:07 2010 +0200
+++ b/web/test/unittest_views_basecontrollers.py Fri Oct 08 07:55:11 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',
@@ -285,26 +285,6 @@
self.assertItemsEqual(usergroups, ['managers'])
self.assertEqual(get_pending_deletes(req), [])
- # def test_custom_attribute_handler(self):
- # def custom_login_edit(self, formparams, value, relations):
- # formparams['login'] = value.upper()
- # relations.append('X login %(login)s')
- # CWUser.custom_login_edit = custom_login_edit
- # try:
- # user = self.user()
- # eid = repr(user.eid)
- # req = self.request()
- # req.form = {
- # 'eid': eid,
- # '__type:'+eid: 'CWUser',
- # 'login:'+eid: u'foo',
- # }
- # path, params = self.expect_redirect_publish(req, 'edit')
- # rset = self.execute('Any L WHERE X eid %(x)s, X login L', {'x': user.eid}, 'x')
- # self.assertEqual(rset[0][0], 'FOO')
- # finally:
- # del CWUser.custom_login_edit
-
def test_redirect_apply_button(self):
redirectrql = rql_for_eid(4012) # whatever
req = self.request()
@@ -323,7 +303,7 @@
self.failUnless(path.startswith('blogentry/'))
eid = path.split('/')[1]
self.assertEqual(params['vid'], 'edition')
- self.assertNotEquals(int(eid), 4012)
+ self.assertNotEqual(int(eid), 4012)
self.assertEqual(params['__redirectrql'], redirectrql)
self.assertEqual(params['__redirectvid'], 'primary')
self.assertEqual(params['__redirectparams'], 'toto=tutu&tata=titi')