test/unittest_vregistry.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Dec 2009 17:10:01 +0100
changeset 4088 23ce2b3fb03d
parent 2826 a4ddd807c5ee
child 4252 6c4f109c2b03
permissions -rw-r--r--
don't use setdefault with a tuple as value, a set is expected
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
     1
"""
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
     2
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
     3
:organization: Logilab
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
     4
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
     6
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
     7
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
from logilab.common.testlib import unittest_main, TestCase
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
from os.path import join
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
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
    13
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
    14
from cubicweb.cwvreg import CubicWebVRegistry, UnknownProperty
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    15
from cubicweb.devtools import TestServerConfiguration
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    16
from cubicweb.interfaces import IMileStone
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    18
from cubes.card.entities import Card
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    19
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
class YesSchema:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
    def __contains__(self, something):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
        return True
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    23
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    24
WEBVIEWSDIR = join(BASE, 'web', 'views')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    25
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
class VRegistryTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
    def setUp(self):
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    29
        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
    30
        self.vreg = CubicWebVRegistry(config)
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    31
        config.bootstrap_cubes()
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    32
        self.vreg.schema = config.load_schema()
1640
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
    def test_load_interface_based_vojects(self):
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    35
        self.vreg.init_registration([WEBVIEWSDIR])
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    36
        self.vreg.load_file(join(BASE, 'entities', '__init__.py'), 'cubicweb.entities.__init__')
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    37
        self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    38
        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
    39
        self.assertEquals(len(self.vreg['views']['primary']), 2)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    40
        self.vreg.initialization_completed()
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    41
        self.assertEquals(len(self.vreg['views']['primary']), 1)
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    42
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
    def test_properties(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
        self.failIf('system.version.cubicweb' in self.vreg['propertydefs'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
        self.failUnless(self.vreg.property_info('system.version.cubicweb'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
        self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    47
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    48
    def test_load_subinterface_based_appobjects(self):
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    49
        self.vreg.reset()
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    50
        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
    51
        # check progressbar was kicked
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    52
        self.failIf(self.vreg['views'].get('progressbar'))
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    53
        class MyCard(Card):
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    54
            __implements__ = (IMileStone,)
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    55
        self.vreg.reset()
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    56
        self.vreg._loadedmods[__name__] = {}
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    57
        self.vreg.register_appobject_class(MyCard)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    58
        self.vreg.register_objects([join(BASE, 'entities', '__init__.py'),
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    59
                                    join(BASE, 'web', 'views', 'iprogress.py')])
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    60
        # check progressbar isn't kicked
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    61
        self.assertEquals(len(self.vreg['views']['progressbar']), 1)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    62
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
    unittest_main()