[devtools] fix self.session._cnx vs self.cnx._cnx confusion after self.login
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 14 Jan 2014 17:30:13 +0100
changeset 9472 ae97167956b1
parent 9471 367fe83d9f98
child 9473 53974a06d646
[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.
devtools/test/unittest_testlib.py
devtools/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):
--- 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