test/unittest_vregistry.py
branchtls-sprint
changeset 1640 65b60f177eb1
parent 1341 9502d02630bf
child 1787 71c143c0ada3
equal deleted inserted replaced
1639:375c857aa0f5 1640:65b60f177eb1
     4 
     4 
     5 from cubicweb import CW_SOFTWARE_ROOT as BASE
     5 from cubicweb import CW_SOFTWARE_ROOT as BASE
     6 from cubicweb.vregistry import VObject
     6 from cubicweb.vregistry import VObject
     7 from cubicweb.cwvreg import CubicWebRegistry, UnknownProperty
     7 from cubicweb.cwvreg import CubicWebRegistry, UnknownProperty
     8 from cubicweb.devtools import TestServerConfiguration
     8 from cubicweb.devtools import TestServerConfiguration
     9 from cubicweb.entities.lib import Card
       
    10 from cubicweb.interfaces import IMileStone
     9 from cubicweb.interfaces import IMileStone
       
    10 
       
    11 from cubes.card.entities import Card
    11 
    12 
    12 class YesSchema:
    13 class YesSchema:
    13     def __contains__(self, something):
    14     def __contains__(self, something):
    14         return True
    15         return True
    15 
    16 
    16 WEBVIEWSDIR = join(BASE, 'web', 'views')
    17 WEBVIEWSDIR = join(BASE, 'web', 'views')
    17     
    18 
    18 class VRegistryTC(TestCase):
    19 class VRegistryTC(TestCase):
    19 
    20 
    20     def setUp(self):
    21     def setUp(self):
    21         config = TestServerConfiguration('data')
    22         config = TestServerConfiguration('data')
    22         self.vreg = CubicWebRegistry(config)
    23         self.vreg = CubicWebRegistry(config)
    23         config.bootstrap_cubes()
    24         config.bootstrap_cubes()
    24         self.vreg.schema = config.load_schema()
    25         self.vreg.schema = config.load_schema()
    25         
    26 
    26     def test_load(self):
    27     def test_load(self):
    27         self.vreg.init_registration([WEBVIEWSDIR])
    28         self.vreg.init_registration([WEBVIEWSDIR])
    28         self.vreg.load_file(join(WEBVIEWSDIR, 'euser.py'), 'cubicweb.web.views.euser')
    29         self.vreg.load_file(join(WEBVIEWSDIR, 'cwuser.py'), 'cubicweb.web.views.cwuser')
    29         self.vreg.load_file(join(WEBVIEWSDIR, 'baseviews.py'), 'cubicweb.web.views.baseviews')
    30         self.vreg.load_file(join(WEBVIEWSDIR, 'baseviews.py'), 'cubicweb.web.views.baseviews')
    30         fpvc = [v for v in self.vreg.registry_objects('views', 'primary')
    31         fpvc = [v for v in self.vreg.registry_objects('views', 'primary')
    31                if v.__module__ == 'cubicweb.web.views.euser'][0]
    32                if v.__module__ == 'cubicweb.web.views.cwuser'][0]
    32         fpv = fpvc(None, None)
    33         fpv = fpvc(None, None)
    33         # don't want a TypeError due to super call
    34         # don't want a TypeError due to super call
    34         self.assertRaises(AttributeError, fpv.render_entity_attributes, None, None)
    35         self.assertRaises(AttributeError, fpv.render_entity_attributes, None, None)
    35 
    36 
    36     def test_load_interface_based_vojects(self):
    37     def test_load_interface_based_vojects(self):
    37         self.vreg.init_registration([WEBVIEWSDIR])
    38         self.vreg.init_registration([WEBVIEWSDIR])
       
    39         self.vreg.load_file(join(BASE, 'entities', '__init__.py'), 'cubicweb.entities.__init__')
    38         self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable')
    40         self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable')
    39         self.vreg.load_file(join(WEBVIEWSDIR, 'baseviews.py'), 'cubicweb.web.views.baseviews')
    41         self.vreg.load_file(join(WEBVIEWSDIR, 'primary.py'), 'cubicweb.web.views.primary')
    40         # check loading baseviews after idownloadable isn't kicking interface based views
       
    41         self.assertEquals(len(self.vreg['views']['primary']), 2)
    42         self.assertEquals(len(self.vreg['views']['primary']), 2)
    42                               
    43         self.vreg.initialization_completed()
       
    44         self.assertEquals(len(self.vreg['views']['primary']), 1)
       
    45 
    43     def test___selectors__compat(self):
    46     def test___selectors__compat(self):
    44         myselector1 = lambda *args: 1
    47         myselector1 = lambda *args: 1
    45         myselector2 = lambda *args: 1
    48         myselector2 = lambda *args: 1
    46         class AnAppObject(VObject):
    49         class AnAppObject(VObject):
    47             __selectors__ = (myselector1, myselector2)
    50             __selectors__ = (myselector1, myselector2)
    61         class MyCard(Card):
    64         class MyCard(Card):
    62             __implements__ = (IMileStone,)
    65             __implements__ = (IMileStone,)
    63         self.vreg.reset()
    66         self.vreg.reset()
    64         self.vreg._loadedmods[__name__] = {}
    67         self.vreg._loadedmods[__name__] = {}
    65         self.vreg.register_vobject_class(MyCard)
    68         self.vreg.register_vobject_class(MyCard)
    66         self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
    69         self.vreg.register_objects([join(BASE, 'entities', '__init__.py'),
       
    70                                     join(BASE, 'web', 'views', 'iprogress.py')])
    67         # check progressbar isn't kicked
    71         # check progressbar isn't kicked
    68         self.assertEquals(len(self.vreg['views']['progressbar']), 1)
    72         self.assertEquals(len(self.vreg['views']['progressbar']), 1)
    69         
    73 
    70 
    74 
    71 if __name__ == '__main__':
    75 if __name__ == '__main__':
    72     unittest_main()
    76     unittest_main()