# HG changeset patch # User Sylvain Thénault # Date 1315303161 -7200 # Node ID 5b3584c5a7c35d689d620eda03a2adc6cf7da9d4 # Parent 98e34ae4cf89d8c1a4eb76de43523eb8be8f26e8 [hooks control] test and fix session.reset_hooks_mode_categories, closes #1908680 diff -r 98e34ae4cf89 -r 5b3584c5a7c3 server/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): diff -r 98e34ae4cf89 -r 5b3584c5a7c3 server/test/unittest_session.py --- 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)')