test/unittest_vregistry.py
author Alexandre Fayolle <alexandre.fayolle@logilab.fr>
Sun, 20 Jun 2010 15:09:42 +0000
branchstable
changeset 5801 355d3945c1f3
parent 5424 8ecbcbff9777
child 5466 b5af2ac0c43c
permissions -rw-r--r--
Use SQL standard ALTER TABLE command (with ADD instead of ADD COLUMN)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4491
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
    18
"""
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
    19
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
    20
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
from logilab.common.testlib import unittest_main, TestCase
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
from os.path import join
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
from cubicweb import CW_SOFTWARE_ROOT as BASE
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    26
from cubicweb.appobject import AppObject
2650
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    27
from cubicweb.cwvreg import CubicWebVRegistry, UnknownProperty
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    28
from cubicweb.devtools import TestServerConfiguration
4490
d45cde54d464 backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252 4485
diff changeset
    29
from cubicweb.devtools.testlib import CubicWebTC
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    30
from cubicweb.interfaces import IMileStone
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    32
from cubes.card.entities import Card
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    33
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
class YesSchema:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    def __contains__(self, something):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
        return True
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    37
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    38
WEBVIEWSDIR = join(BASE, 'web', 'views')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    39
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
class VRegistryTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
    def setUp(self):
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    43
        config = TestServerConfiguration('data')
2650
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    44
        self.vreg = CubicWebVRegistry(config)
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    45
        config.bootstrap_cubes()
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    46
        self.vreg.schema = config.load_schema()
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    47
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
    def test_load_interface_based_vojects(self):
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    49
        self.vreg.init_registration([WEBVIEWSDIR])
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    50
        self.vreg.load_file(join(BASE, 'entities', '__init__.py'), 'cubicweb.entities.__init__')
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    51
        self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    52
        self.vreg.load_file(join(WEBVIEWSDIR, 'primary.py'), 'cubicweb.web.views.primary')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
        self.assertEquals(len(self.vreg['views']['primary']), 2)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    54
        self.vreg.initialization_completed()
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    55
        self.assertEquals(len(self.vreg['views']['primary']), 1)
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    56
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    57
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    58
    def test_load_subinterface_based_appobjects(self):
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    59
        self.vreg.reset()
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    60
        self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    61
        # check progressbar was kicked
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    62
        self.failIf(self.vreg['views'].get('progressbar'))
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    63
        class MyCard(Card):
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    64
            __implements__ = (IMileStone,)
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    65
        self.vreg.reset()
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    66
        self.vreg._loadedmods[__name__] = {}
4491
a0f48c31b58a kill register_appobject_class method, simplifying autoregistration. Update test accordingly (test which manually registers object should also properly call there __register__ method). Drop the disable-appobjects config file entry: no one used it since its introduction years ago.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4490
diff changeset
    67
        self.vreg.register(MyCard)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    68
        self.vreg.register_objects([join(BASE, 'entities', '__init__.py'),
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    69
                                    join(BASE, 'web', 'views', 'iprogress.py')])
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    70
        # check progressbar isn't kicked
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    71
        self.assertEquals(len(self.vreg['views']['progressbar']), 1)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    72
4485
5f99eb0b99f7 initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    73
    def test_properties(self):
5f99eb0b99f7 initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    74
        self.failIf('system.version.cubicweb' in self.vreg['propertydefs'])
5f99eb0b99f7 initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    75
        self.failUnless(self.vreg.property_info('system.version.cubicweb'))
5f99eb0b99f7 initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    76
        self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')
5f99eb0b99f7 initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    77
4490
d45cde54d464 backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252 4485
diff changeset
    78
d45cde54d464 backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252 4485
diff changeset
    79
class CWVregTC(CubicWebTC):
4485
5f99eb0b99f7 initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    80
5f99eb0b99f7 initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    81
    def test_property_default_overriding(self):
5f99eb0b99f7 initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    82
        # see data/views.py
5f99eb0b99f7 initialize property once initialization has been fully completed, close #666573
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
    83
        from cubicweb.web.views.xmlrss import RSSIconBox
4490
d45cde54d464 backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252 4485
diff changeset
    84
        self.assertEquals(self.vreg.property_info(RSSIconBox._cwpropkey('visible'))['default'], True)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
    unittest_main()