author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Thu, 14 Feb 2013 15:29:20 +0100 | |
changeset 8693 | a6ca96ec8693 |
parent 8594 | 001159e2e4f3 |
child 8694 | d901c36bcfce |
permissions | -rw-r--r-- |
7192
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
8594
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
2 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
7192
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
# |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
# This file is part of CubicWeb. |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
# |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
# any later version. |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
# |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
# details. |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
16 |
# |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
19 |
"""functional tests for core hooks |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
20 |
|
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
21 |
Note: |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
22 |
syncschema.py hooks are mostly tested in server/test/unittest_migrations.py |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
23 |
""" |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
24 |
from __future__ import with_statement |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
25 |
|
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
26 |
from cubicweb import ValidationError |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
27 |
from cubicweb.devtools.testlib import CubicWebTC |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
28 |
|
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
29 |
class CWPropertyHooksTC(CubicWebTC): |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
30 |
|
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
31 |
def test_unexistant_cwproperty(self): |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
32 |
with self.assertRaises(ValidationError) as cm: |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
33 |
self.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U') |
8594
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
34 |
cm.exception.translate(unicode) |
7192
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
35 |
self.assertEqual(cm.exception.errors, {'pkey-subject': 'unknown property key bla.bla'}) |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
36 |
with self.assertRaises(ValidationError) as cm: |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
37 |
self.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop"') |
8594
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
38 |
cm.exception.translate(unicode) |
7192
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
39 |
self.assertEqual(cm.exception.errors, {'pkey-subject': 'unknown property key bla.bla'}) |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
40 |
|
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
41 |
def test_site_wide_cwproperty(self): |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
42 |
with self.assertRaises(ValidationError) as cm: |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
43 |
self.execute('INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U') |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
44 |
self.assertEqual(cm.exception.errors, {'for_user-subject': "site-wide property can't be set for user"}) |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
45 |
|
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
46 |
def test_system_cwproperty(self): |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
47 |
with self.assertRaises(ValidationError) as cm: |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
48 |
self.execute('INSERT CWProperty X: X pkey "system.version.cubicweb", X value "hop", X for_user U') |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
49 |
self.assertEqual(cm.exception.errors, {'for_user-subject': "site-wide property can't be set for user"}) |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
50 |
|
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
51 |
def test_bad_type_cwproperty(self): |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
52 |
with self.assertRaises(ValidationError) as cm: |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
53 |
self.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U') |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
54 |
self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'}) |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
55 |
with self.assertRaises(ValidationError) as cm: |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
56 |
self.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop"') |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
57 |
self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'}) |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
58 |
|
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
59 |
if __name__ == '__main__': |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
60 |
from logilab.common.testlib import unittest_main |
9e92c8558fea
[test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
61 |
unittest_main() |