test/unittest_vregistry.py
author sylvain.thenault@logilab.fr
Thu, 12 Mar 2009 20:45:39 +0100
branchtls-sprint
changeset 1110 c71997f514ba
parent 777 39695e98ba35
child 1341 9502d02630bf
permissions -rw-r--r--
fix password widget: do not duplicate dom id, fix confirm field name
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.entities.lib import Card
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    10
from cubicweb.interfaces import IMileStone
0
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
class YesSchema:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
    def __contains__(self, something):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
        return True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
    
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    16
class VRegistryTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
    def setUp(self):
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    19
        config = TestServerConfiguration('data')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
        self.vreg = CubicWebRegistry(config)
777
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    21
        config.bootstrap_cubes()
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    22
        self.vreg.schema = config.load_schema()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
    def test_load(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
        self.vreg.load_file(join(BASE, 'web', 'views'), 'euser.py')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
        self.vreg.load_file(join(BASE, 'web', 'views'), 'baseviews.py')
631
99f5852f8604 major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    27
        fpvc = [v for v in self.vreg.registry_objects('views', 'primary')
633
087e3f1e87c8 more selectors update
sylvain.thenault@logilab.fr
parents: 631
diff changeset
    28
               if v.__module__ == 'cubicweb.web.views.euser'][0]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
        fpv = fpvc(None, None)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
        # don't want a TypeError due to super call
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
        self.assertRaises(AttributeError, fpv.render_entity_attributes, None, None)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
    def test_load_interface_based_vojects(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
        self.vreg.load_file(join(BASE, 'web', 'views'), 'idownloadable.py')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
        self.vreg.load_file(join(BASE, 'web', 'views'), 'baseviews.py')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
        # check loading baseviews after idownloadable isn't kicking interface based views
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        self.assertEquals(len(self.vreg['views']['primary']), 2)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
                              
740
e92c19eaf63f updat etest
sylvain.thenault@logilab.fr
parents: 633
diff changeset
    39
    def test___selectors__compat(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
        myselector1 = lambda *args: 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
        myselector2 = lambda *args: 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
        class AnAppObject(VObject):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
            __selectors__ = (myselector1, myselector2)
740
e92c19eaf63f updat etest
sylvain.thenault@logilab.fr
parents: 633
diff changeset
    44
        AnAppObject.build___select__()
e92c19eaf63f updat etest
sylvain.thenault@logilab.fr
parents: 633
diff changeset
    45
        self.assertEquals(AnAppObject.__select__(AnAppObject), 2)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
    def test_properties(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
        self.failIf('system.version.cubicweb' in self.vreg['propertydefs'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
        self.failUnless(self.vreg.property_info('system.version.cubicweb'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
        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
    51
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    52
    def test_load_subinterface_based_vobjects(self):
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    53
        self.vreg.reset()
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    54
        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
    55
        # check progressbar was kicked
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    56
        self.failIf(self.vreg['views'].get('progressbar'))
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    57
        class MyCard(Card):
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    58
            __implements__ = (IMileStone,)
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_vobject_class(MyCard)
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    61
        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
    62
        # check progressbar isn't kicked
39695e98ba35 test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents: 750
diff changeset
    63
        self.assertEquals(len(self.vreg['views']['progressbar']), 1)
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
    unittest_main()