[hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680 stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 06 Sep 2011 11:59:21 +0200
branchstable
changeset 7757 5b3584c5a7c3
parent 7756 98e34ae4cf89
child 7758 1b8b83ff9f6b
[hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680
server/session.py
server/test/unittest_session.py
--- a/server/session.py	Mon Sep 05 16:48:37 2011 +0200
+++ b/server/session.py	Tue Sep 06 11:59:21 2011 +0200
@@ -636,12 +636,14 @@
         if txstore.ctx_count == 0:
             self._clear_thread_storage(txstore)
         else:
-            if categories:
-                if mode is self.HOOKS_DENY_ALL:
-                    return self.disable_hook_categories(*categories)
-                else:
-                    return self.enable_hook_categories(*categories)
-            self.set_hooks_mode(oldmode)
+            try:
+                if categories:
+                    if mode is self.HOOKS_DENY_ALL:
+                        return self.disable_hook_categories(*categories)
+                    else:
+                        return self.enable_hook_categories(*categories)
+            finally:
+                self.set_hooks_mode(oldmode)
 
     @property
     def disabled_hook_categories(self):
--- a/server/test/unittest_session.py	Mon Sep 05 16:48:37 2011 +0200
+++ b/server/test/unittest_session.py	Tue Sep 06 11:59:21 2011 +0200
@@ -73,10 +73,20 @@
             self.assertEqual(session.hooks_mode, session.HOOKS_DENY_ALL)
             self.assertEqual(session.disabled_hook_categories, set())
             self.assertEqual(session.enabled_hook_categories, set(('metadata',)))
+            with hooks_control(session, session.HOOKS_ALLOW_ALL, 'integrity'):
+                self.assertEqual(session.hooks_mode, session.HOOKS_ALLOW_ALL)
+                self.assertEqual(session.disabled_hook_categories, set(('integrity',)))
+                self.assertEqual(session.enabled_hook_categories, set(('metadata',))) # not changed in such case
+            self.assertEqual(session.hooks_mode, session.HOOKS_DENY_ALL)
+            self.assertEqual(session.disabled_hook_categories, set())
+            self.assertEqual(session.enabled_hook_categories, set(('metadata',)))
         # leaving context manager with no transaction running should reset the
         # transaction local storage (and associated cnxset)
         self.assertEqual(session._tx_data, {})
         self.assertEqual(session.cnxset, None)
+        self.assertEqual(session.hooks_mode, session.HOOKS_ALLOW_ALL)
+        self.assertEqual(session.disabled_hook_categories, set())
+        self.assertEqual(session.enabled_hook_categories, set())
 
     def test_build_descr(self):
         rset = self.execute('(Any U,L WHERE U login L) UNION (Any G,N WHERE G name N, G is CWGroup)')