cubicweb/hooks/test/unittest_syncsession.py
changeset 11057 0b59724cb3f2
parent 10724 aa3eedba866c
child 11129 97095348b3ee
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
       
     1 # -*- coding: utf-8 -*-
       
     2 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     4 #
       
     5 # This file is part of CubicWeb.
       
     6 #
       
     7 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     8 # terms of the GNU Lesser General Public License as published by the Free
       
     9 # Software Foundation, either version 2.1 of the License, or (at your option)
       
    10 # any later version.
       
    11 #
       
    12 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    14 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    15 # details.
       
    16 #
       
    17 # You should have received a copy of the GNU Lesser General Public License along
       
    18 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    19 """functional tests for core hooks
       
    20 
       
    21 Note:
       
    22   syncschema.py hooks are mostly tested in server/test/unittest_migrations.py
       
    23 """
       
    24 
       
    25 from six import text_type
       
    26 
       
    27 from cubicweb import ValidationError
       
    28 from cubicweb.devtools.testlib import CubicWebTC
       
    29 
       
    30 class CWPropertyHooksTC(CubicWebTC):
       
    31 
       
    32     def test_unexistant_cwproperty(self):
       
    33         with self.admin_access.web_request() as req:
       
    34             with self.assertRaises(ValidationError) as cm:
       
    35                 req.execute('INSERT CWProperty X: X pkey "bla.bla", '
       
    36                             'X value "hop", X for_user U')
       
    37             cm.exception.translate(text_type)
       
    38             self.assertEqual(cm.exception.errors,
       
    39                              {'pkey-subject': 'unknown property key bla.bla'})
       
    40 
       
    41             with self.assertRaises(ValidationError) as cm:
       
    42                 req.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop"')
       
    43             cm.exception.translate(text_type)
       
    44             self.assertEqual(cm.exception.errors,
       
    45                              {'pkey-subject': 'unknown property key bla.bla'})
       
    46 
       
    47     def test_site_wide_cwproperty(self):
       
    48         with self.admin_access.web_request() as req:
       
    49             with self.assertRaises(ValidationError) as cm:
       
    50                 req.execute('INSERT CWProperty X: X pkey "ui.site-title", '
       
    51                             'X value "hop", X for_user U')
       
    52             self.assertEqual(cm.exception.errors,
       
    53                              {'for_user-subject': "site-wide property can't be set for user"})
       
    54 
       
    55     def test_system_cwproperty(self):
       
    56         with self.admin_access.web_request() as req:
       
    57             with self.assertRaises(ValidationError) as cm:
       
    58                 req.execute('INSERT CWProperty X: X pkey "system.version.cubicweb", '
       
    59                             'X value "hop", X for_user U')
       
    60             self.assertEqual(cm.exception.errors,
       
    61                              {'for_user-subject': "site-wide property can't be set for user"})
       
    62 
       
    63     def test_bad_type_cwproperty(self):
       
    64         with self.admin_access.web_request() as req:
       
    65             with self.assertRaises(ValidationError) as cm:
       
    66                 req.execute('INSERT CWProperty X: X pkey "ui.language", '
       
    67                             'X value "hop", X for_user U')
       
    68             self.assertEqual(cm.exception.errors,
       
    69                              {'value-subject': u'unauthorized value'})
       
    70             with self.assertRaises(ValidationError) as cm:
       
    71                 req.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop"')
       
    72             self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'})
       
    73 
       
    74 if __name__ == '__main__':
       
    75     from logilab.common.testlib import unittest_main
       
    76     unittest_main()