cubicweb/server/test/unittest_session.py
changeset 11919 3a6746dfc57f
equal deleted inserted replaced
11918:a88101bf9f87 11919:3a6746dfc57f
       
     1 # copyright 2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 
       
    19 from cubicweb.devtools.testlib import CubicWebTC
       
    20 from cubicweb.server import session
       
    21 
       
    22 
       
    23 class HooksControlTC(CubicWebTC):
       
    24 
       
    25     def test_hooks_control(self):
       
    26         with self.admin_access.repo_cnx() as cnx:
       
    27             self.assertEqual(cnx._hooks_mode, session.HOOKS_ALLOW_ALL)
       
    28             self.assertEqual(cnx._hooks_categories, set())
       
    29 
       
    30             with cnx.deny_all_hooks_but('metadata'):
       
    31                 self.assertEqual(cnx._hooks_mode, session.HOOKS_DENY_ALL)
       
    32                 self.assertEqual(cnx._hooks_categories, set(['metadata']))
       
    33 
       
    34                 with cnx.deny_all_hooks_but():
       
    35                     self.assertEqual(cnx._hooks_categories, set())
       
    36                 self.assertEqual(cnx._hooks_categories, set(['metadata']))
       
    37 
       
    38                 with cnx.deny_all_hooks_but('integrity'):
       
    39                     self.assertEqual(cnx._hooks_categories, set(['integrity']))
       
    40                 self.assertEqual(cnx._hooks_categories, set(['metadata']))
       
    41 
       
    42                 with cnx.allow_all_hooks_but('integrity'):
       
    43                     self.assertEqual(cnx._hooks_mode, session.HOOKS_ALLOW_ALL)
       
    44                     self.assertEqual(cnx._hooks_categories, set(['integrity']))
       
    45                 self.assertEqual(cnx._hooks_mode, session.HOOKS_DENY_ALL)
       
    46                 self.assertEqual(cnx._hooks_categories, set(['metadata']))
       
    47 
       
    48             self.assertEqual(cnx._hooks_mode, session.HOOKS_ALLOW_ALL)
       
    49             self.assertEqual(cnx._hooks_categories, set())
       
    50 
       
    51 
       
    52 if __name__ == '__main__':
       
    53     import unittest
       
    54     unittest.main()