hooks/test/unittest_syncsession.py
changeset 9863 3fbad401eb61
parent 8694 d901c36bcfce
child 10724 aa3eedba866c
child 11097 900c27ea30e9
equal deleted inserted replaced
9862:f97a65c29d82 9863:3fbad401eb61
     1 # -*- coding: utf-8 -*-
     1 # -*- coding: utf-8 -*-
     2 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     4 #
     4 #
     5 # This file is part of CubicWeb.
     5 # This file is part of CubicWeb.
     6 #
     6 #
     7 # CubicWeb is free software: you can redistribute it and/or modify it under the
     7 # CubicWeb is free software: you can redistribute it and/or modify it under the
    26 from cubicweb.devtools.testlib import CubicWebTC
    26 from cubicweb.devtools.testlib import CubicWebTC
    27 
    27 
    28 class CWPropertyHooksTC(CubicWebTC):
    28 class CWPropertyHooksTC(CubicWebTC):
    29 
    29 
    30     def test_unexistant_cwproperty(self):
    30     def test_unexistant_cwproperty(self):
    31         with self.assertRaises(ValidationError) as cm:
    31         with self.admin_access.web_request() as req:
    32             self.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U')
    32             with self.assertRaises(ValidationError) as cm:
    33         cm.exception.translate(unicode)
    33                 req.execute('INSERT CWProperty X: X pkey "bla.bla", '
    34         self.assertEqual(cm.exception.errors, {'pkey-subject': 'unknown property key bla.bla'})
    34                             'X value "hop", X for_user U')
    35         with self.assertRaises(ValidationError) as cm:
    35             cm.exception.translate(unicode)
    36             self.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop"')
    36             self.assertEqual(cm.exception.errors,
    37         cm.exception.translate(unicode)
    37                              {'pkey-subject': 'unknown property key bla.bla'})
    38         self.assertEqual(cm.exception.errors, {'pkey-subject': 'unknown property key bla.bla'})
    38 
       
    39             with self.assertRaises(ValidationError) as cm:
       
    40                 req.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop"')
       
    41             cm.exception.translate(unicode)
       
    42             self.assertEqual(cm.exception.errors,
       
    43                              {'pkey-subject': 'unknown property key bla.bla'})
    39 
    44 
    40     def test_site_wide_cwproperty(self):
    45     def test_site_wide_cwproperty(self):
    41         with self.assertRaises(ValidationError) as cm:
    46         with self.admin_access.web_request() as req:
    42             self.execute('INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U')
    47             with self.assertRaises(ValidationError) as cm:
    43         self.assertEqual(cm.exception.errors, {'for_user-subject': "site-wide property can't be set for user"})
    48                 req.execute('INSERT CWProperty X: X pkey "ui.site-title", '
       
    49                             'X value "hop", X for_user U')
       
    50             self.assertEqual(cm.exception.errors,
       
    51                              {'for_user-subject': "site-wide property can't be set for user"})
    44 
    52 
    45     def test_system_cwproperty(self):
    53     def test_system_cwproperty(self):
    46         with self.assertRaises(ValidationError) as cm:
    54         with self.admin_access.web_request() as req:
    47             self.execute('INSERT CWProperty X: X pkey "system.version.cubicweb", X value "hop", X for_user U')
    55             with self.assertRaises(ValidationError) as cm:
    48         self.assertEqual(cm.exception.errors, {'for_user-subject': "site-wide property can't be set for user"})
    56                 req.execute('INSERT CWProperty X: X pkey "system.version.cubicweb", '
       
    57                             'X value "hop", X for_user U')
       
    58             self.assertEqual(cm.exception.errors,
       
    59                              {'for_user-subject': "site-wide property can't be set for user"})
    49 
    60 
    50     def test_bad_type_cwproperty(self):
    61     def test_bad_type_cwproperty(self):
    51         with self.assertRaises(ValidationError) as cm:
    62         with self.admin_access.web_request() as req:
    52             self.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U')
    63             with self.assertRaises(ValidationError) as cm:
    53         self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'})
    64                 req.execute('INSERT CWProperty X: X pkey "ui.language", '
    54         with self.assertRaises(ValidationError) as cm:
    65                             'X value "hop", X for_user U')
    55             self.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop"')
    66             self.assertEqual(cm.exception.errors,
    56         self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'})
    67                              {'value-subject': u'unauthorized value'})
       
    68             with self.assertRaises(ValidationError) as cm:
       
    69                 req.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop"')
       
    70             self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'})
    57 
    71 
    58 if __name__ == '__main__':
    72 if __name__ == '__main__':
    59     from logilab.common.testlib import unittest_main
    73     from logilab.common.testlib import unittest_main
    60     unittest_main()
    74     unittest_main()