cubicweb/hooks/test/unittest_syncsession.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Fri, 23 Sep 2016 16:04:32 +0200
changeset 11478 1817f8946c22
parent 11350 de466349b742
child 12126 be8636d12afd
permissions -rw-r--r--
[tox] Have less test environments This is to reduce the load on CI server because of parallel clones of the repository in Docker containers. Only keep "server", and "web" environments separated. All other prior environments are in "misc". To avoid duplicate entries in requirements files, move them all in a "requirements" directory (this appears to be a "common" practice, see e.g. Celery). Adjustments in tests: * Rename cubicweb/hooks/test/unittest_notification.py so that it does not conflict with cubicweb/sobjects/test/unittest_notification.py during test discovery as they would have the same module name but different __file__ attribute. * Add "comment" cube to the list of expected cubes in unittest_cwconfig.py as this cube is pulled by requirements/test-mist.txt. Closes #15440662.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 -*-
11348
70337ad23145 pep8 + docstrings and comments improvments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
     2
# copyright 2003-2016 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
10724
aa3eedba866c [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9863
diff changeset
    25
from six import text_type
aa3eedba866c [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9863
diff changeset
    26
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
    27
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
    28
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
    29
11348
70337ad23145 pep8 + docstrings and comments improvments
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11129
diff changeset
    30
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
    31
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
    32
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
    def test_unexistant_cwproperty(self):
9863
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    34
        with self.admin_access.web_request() as req:
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    35
            with self.assertRaises(ValidationError) as cm:
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    36
                req.execute('INSERT CWProperty X: X pkey "bla.bla", '
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    37
                            'X value "hop", X for_user U')
10724
aa3eedba866c [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9863
diff changeset
    38
            cm.exception.translate(text_type)
9863
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    39
            self.assertEqual(cm.exception.errors,
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    40
                             {'pkey-subject': 'unknown property key bla.bla'})
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    41
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    42
            with self.assertRaises(ValidationError) as cm:
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    43
                req.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop"')
10724
aa3eedba866c [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9863
diff changeset
    44
            cm.exception.translate(text_type)
9863
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    45
            self.assertEqual(cm.exception.errors,
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    46
                             {'pkey-subject': 'unknown property key bla.bla'})
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
    47
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
    def test_site_wide_cwproperty(self):
9863
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    49
        with self.admin_access.web_request() as req:
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    50
            with self.assertRaises(ValidationError) as cm:
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    51
                req.execute('INSERT CWProperty X: X pkey "ui.site-title", '
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    52
                            'X value "hop", X for_user U')
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    53
            self.assertEqual(cm.exception.errors,
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    54
                             {'for_user-subject': "site-wide property can't be set for user"})
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
    55
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
    def test_system_cwproperty(self):
9863
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    57
        with self.admin_access.web_request() as req:
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    58
            with self.assertRaises(ValidationError) as cm:
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    59
                req.execute('INSERT CWProperty X: X pkey "system.version.cubicweb", '
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    60
                            'X value "hop", X for_user U')
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    61
            self.assertEqual(cm.exception.errors,
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    62
                             {'for_user-subject': "site-wide property can't be set for user"})
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
    63
9e92c8558fea [test, cw props] ensure we can't add user specific / system-wide properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
    def test_bad_type_cwproperty(self):
9863
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    65
        with self.admin_access.web_request() as req:
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    66
            with self.assertRaises(ValidationError) as cm:
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    67
                req.execute('INSERT CWProperty X: X pkey "ui.language", '
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    68
                            'X value "hop", X for_user U')
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    69
            self.assertEqual(cm.exception.errors,
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    70
                             {'value-subject': u'unauthorized value'})
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    71
            with self.assertRaises(ValidationError) as cm:
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    72
                req.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop"')
3fbad401eb61 [tests/syncsession] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    73
            self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'})
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
    74
11097
900c27ea30e9 [cwvreg] Fix propertyvalues hot updates
Christophe de Vienne <christophe@unlish.com>
parents: 9863
diff changeset
    75
    def test_vreg_propertyvalues_update(self):
900c27ea30e9 [cwvreg] Fix propertyvalues hot updates
Christophe de Vienne <christophe@unlish.com>
parents: 9863
diff changeset
    76
        self.vreg.register_property(
900c27ea30e9 [cwvreg] Fix propertyvalues hot updates
Christophe de Vienne <christophe@unlish.com>
parents: 9863
diff changeset
    77
            'test.int', type='Int', help='', sitewide=True)
900c27ea30e9 [cwvreg] Fix propertyvalues hot updates
Christophe de Vienne <christophe@unlish.com>
parents: 9863
diff changeset
    78
        with self.admin_access.repo_cnx() as cnx:
900c27ea30e9 [cwvreg] Fix propertyvalues hot updates
Christophe de Vienne <christophe@unlish.com>
parents: 9863
diff changeset
    79
            cnx.execute('INSERT CWProperty X: X pkey "test.int", X value "42"')
900c27ea30e9 [cwvreg] Fix propertyvalues hot updates
Christophe de Vienne <christophe@unlish.com>
parents: 9863
diff changeset
    80
            cnx.commit()
900c27ea30e9 [cwvreg] Fix propertyvalues hot updates
Christophe de Vienne <christophe@unlish.com>
parents: 9863
diff changeset
    81
        self.assertEqual(self.vreg.property_value('test.int'), 42)
900c27ea30e9 [cwvreg] Fix propertyvalues hot updates
Christophe de Vienne <christophe@unlish.com>
parents: 9863
diff changeset
    82
11350
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    83
    def test_sync_user_props(self):
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    84
        with self.admin_access.client_cnx() as cnx:
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    85
            self.assertNotIn('ui.language', cnx.user.properties)
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    86
            cnx.user.set_property(u'ui.language', u'fr')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    87
            self.assertNotIn('ui.language', cnx.user.properties)
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    88
            cnx.commit()
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    89
            self.assertEqual(cnx.user.properties['ui.language'], 'fr')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    90
            cnx.user.set_property(u'ui.language', u'en')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    91
            self.assertEqual(cnx.user.properties['ui.language'], 'fr')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    92
            cnx.commit()
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    93
            self.assertEqual(cnx.user.properties['ui.language'], 'en')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    94
            cnx.execute('DELETE CWProperty X WHERE X for_user U, U eid %(u)s',
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    95
                        {'u': cnx.user.eid})
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    96
            self.assertEqual(cnx.user.properties['ui.language'], 'en')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    97
            cnx.commit()
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    98
            self.assertNotIn('ui.language', cnx.user.properties)
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
    99
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   100
    def test_sync_sitewide_props(self):
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   101
        with self.admin_access.client_cnx() as cnx:
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   102
            self.assertNotIn('ui.language', cnx.vreg['propertyvalues'])
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   103
            cwprop = cnx.create_entity('CWProperty', pkey=u'ui.language', value=u'fr')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   104
            self.assertNotIn('ui.language', cnx.vreg['propertyvalues'])
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   105
            cnx.commit()
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   106
            self.assertEqual(cnx.vreg['propertyvalues']['ui.language'], 'fr')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   107
            cwprop.cw_set(value=u'en')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   108
            self.assertEqual(cnx.vreg['propertyvalues']['ui.language'], 'fr')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   109
            cnx.commit()
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   110
            self.assertEqual(cnx.vreg['propertyvalues']['ui.language'], 'en')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   111
            cwprop.cw_delete()
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   112
            self.assertEqual(cnx.vreg['propertyvalues']['ui.language'], 'en')
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   113
            cnx.commit()
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   114
            self.assertNotIn('ui.language', cnx.vreg['propertyvalues'])
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   115
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   116
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   117
class UserGroupsSyncTC(CubicWebTC):
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   118
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   119
    def test_sync_groups(self):
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   120
        with self.admin_access.client_cnx() as cnx:
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   121
            cnx.execute('SET U in_group G WHERE G name "users", U eid %(u)s',
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   122
                        {'u': cnx.user.eid})
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   123
            self.assertEqual(cnx.user.groups, set(['managers']))
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   124
            cnx.commit()
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   125
            self.assertEqual(cnx.user.groups, set(['managers', 'users']))
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   126
            cnx.execute('DELETE U in_group G WHERE G name "users", U eid %(u)s',
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   127
                        {'u': cnx.user.eid})
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   128
            self.assertEqual(cnx.user.groups, set(['managers', 'users']))
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   129
            cnx.commit()
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   130
            self.assertEqual(cnx.user.groups, set(['managers']))
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   131
11097
900c27ea30e9 [cwvreg] Fix propertyvalues hot updates
Christophe de Vienne <christophe@unlish.com>
parents: 9863
diff changeset
   132
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
   133
if __name__ == '__main__':
11350
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   134
    import unittest
de466349b742 [hooks] Add a bunch of tests for session synchronization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11348
diff changeset
   135
    unittest.main()