# HG changeset patch # User Julien Cristau # Date 1389717013 -3600 # Node ID ae97167956b1465bd7c02f3b44d37c7d1ebffc23 # Parent 367fe83d9f986ea4e3fe1c427df3f778d813ac68 [devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login Make sure the client connection and the session refer to the same server connection. diff -r 367fe83d9f98 -r ae97167956b1 devtools/test/unittest_testlib.py --- a/devtools/test/unittest_testlib.py Thu Jan 23 18:26:16 2014 +0100 +++ b/devtools/test/unittest_testlib.py Tue Jan 14 17:30:13 2014 +0100 @@ -189,6 +189,33 @@ self.assertIn(AnAppobject, self.vreg['hip']['hop']) self.assertNotIn(AnAppobject, self.vreg['hip']['hop']) + def test_login(self): + """Calling login should not break self.session hook control""" + self.hook_executed = False + babar = self.create_user(self.request(), 'babar') + self.commit() + + from cubicweb.server import hook + from cubicweb.predicates import is_instance + + class MyHook(hook.Hook): + __regid__ = 'whatever' + __select__ = hook.Hook.__select__ & is_instance('CWProperty') + category = 'test-hook' + events = ('after_add_entity',) + test = self + + def __call__(self): + self.test.hook_executed = True + + self.login('babar') + with self.temporary_appobjects(MyHook): + with self.session.allow_all_hooks_but('test-hook'): + req = self.request() + prop = req.create_entity('CWProperty', pkey=u'ui.language', value=u'en') + self.commit() + self.assertFalse(self.hook_executed) + class RepoAccessTC(CubicWebTC): def test_repo_connection(self): diff -r 367fe83d9f98 -r ae97167956b1 devtools/testlib.py --- a/devtools/testlib.py Thu Jan 23 18:26:16 2014 +0100 +++ b/devtools/testlib.py Tue Jan 14 17:30:13 2014 +0100 @@ -316,6 +316,8 @@ # can't call set_cnx as the Connection is not managed by the # session. session._Session__threaddata.cnx = self._admin_clt_cnx._cnx + else: + session._Session__threaddata.cnx = self.cnx._cnx session.set_cnxset() return session