hooks/test/unittest_syncsession.py
branchstable
changeset 7192 9e92c8558fea
child 8556 bbe0d6985e59
equal deleted inserted replaced
7191:1e2d8e4d2c7b 7192:9e92c8558fea
       
     1 # -*- coding: utf-8 -*-
       
     2 # copyright 2003-2011 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 from __future__ import with_statement
       
    25 
       
    26 from cubicweb import ValidationError
       
    27 from cubicweb.devtools.testlib import CubicWebTC
       
    28 
       
    29 class CWPropertyHooksTC(CubicWebTC):
       
    30 
       
    31     def test_unexistant_cwproperty(self):
       
    32         with self.assertRaises(ValidationError) as cm:
       
    33             self.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U')
       
    34         self.assertEqual(cm.exception.errors, {'pkey-subject': 'unknown property key bla.bla'})
       
    35         with self.assertRaises(ValidationError) as cm:
       
    36             self.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop"')
       
    37         self.assertEqual(cm.exception.errors, {'pkey-subject': 'unknown property key bla.bla'})
       
    38 
       
    39     def test_site_wide_cwproperty(self):
       
    40         with self.assertRaises(ValidationError) as cm:
       
    41             self.execute('INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U')
       
    42         self.assertEqual(cm.exception.errors, {'for_user-subject': "site-wide property can't be set for user"})
       
    43 
       
    44     def test_system_cwproperty(self):
       
    45         with self.assertRaises(ValidationError) as cm:
       
    46             self.execute('INSERT CWProperty X: X pkey "system.version.cubicweb", X value "hop", X for_user U')
       
    47         self.assertEqual(cm.exception.errors, {'for_user-subject': "site-wide property can't be set for user"})
       
    48 
       
    49     def test_bad_type_cwproperty(self):
       
    50         with self.assertRaises(ValidationError) as cm:
       
    51             self.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U')
       
    52         self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'})
       
    53         with self.assertRaises(ValidationError) as cm:
       
    54             self.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop"')
       
    55         self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'})
       
    56 
       
    57 if __name__ == '__main__':
       
    58     from logilab.common.testlib import unittest_main
       
    59     unittest_main()