test/unittest_vregistry.py
author sylvain.thenault@logilab.fr
Thu, 14 May 2009 12:49:04 +0200
changeset 1810 e95e876be17c
parent 1787 71c143c0ada3
child 1977 606923dff11b
permissions -rw-r--r--
merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
from logilab.common.testlib import unittest_main, TestCase
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
from os.path import join
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
from cubicweb import CW_SOFTWARE_ROOT as BASE
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
from cubicweb.vregistry import VObject
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
from cubicweb.cwvreg import CubicWebRegistry, UnknownProperty
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
     8
from cubicweb.devtools import TestServerConfiguration
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
     9
from cubicweb.interfaces import IMileStone
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    11
from cubes.card.entities import Card
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    12
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
class YesSchema:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
    def __contains__(self, something):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
        return True
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    16
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    17
WEBVIEWSDIR = join(BASE, 'web', 'views')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    18
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
class VRegistryTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
    def setUp(self):
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    22
        config = TestServerConfiguration('data')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
        self.vreg = CubicWebRegistry(config)
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    24
        config.bootstrap_cubes()
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    25
        self.vreg.schema = config.load_schema()
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    26
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
    def test_load_interface_based_vojects(self):
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    28
        self.vreg.init_registration([WEBVIEWSDIR])
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    29
        self.vreg.load_file(join(BASE, 'entities', '__init__.py'), 'cubicweb.entities.__init__')
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    30
        self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    31
        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
    32
        self.assertEquals(len(self.vreg['views']['primary']), 2)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    33
        self.vreg.initialization_completed()
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    34
        self.assertEquals(len(self.vreg['views']['primary']), 1)
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    35
740
e92c19eaf63f updat etest
sylvain.thenault@logilab.fr
parents: 633
diff changeset
    36
    def test___selectors__compat(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        myselector1 = lambda *args: 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
        myselector2 = lambda *args: 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
        class AnAppObject(VObject):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
            __selectors__ = (myselector1, myselector2)
740
e92c19eaf63f updat etest
sylvain.thenault@logilab.fr
parents: 633
diff changeset
    41
        AnAppObject.build___select__()
e92c19eaf63f updat etest
sylvain.thenault@logilab.fr
parents: 633
diff changeset
    42
        self.assertEquals(AnAppObject.__select__(AnAppObject), 2)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
    def test_properties(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
        self.failIf('system.version.cubicweb' in self.vreg['propertydefs'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
        self.failUnless(self.vreg.property_info('system.version.cubicweb'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
        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
    48
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    49
    def test_load_subinterface_based_vobjects(self):
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    50
        self.vreg.reset()
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    51
        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
    52
        # check progressbar was kicked
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    53
        self.failIf(self.vreg['views'].get('progressbar'))
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    54
        class MyCard(Card):
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    55
            __implements__ = (IMileStone,)
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    56
        self.vreg.reset()
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 777
diff changeset
    57
        self.vreg._loadedmods[__name__] = {}
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    58
        self.vreg.register_vobject_class(MyCard)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    59
        self.vreg.register_objects([join(BASE, 'entities', '__init__.py'),
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    60
                                    join(BASE, 'web', 'views', 'iprogress.py')])
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    61
        # check progressbar isn't kicked
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    62
        self.assertEquals(len(self.vreg['views']['progressbar']), 1)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    63
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
    unittest_main()