test/unittest_vregistry.py
branchstable
changeset 4485 5f99eb0b99f7
parent 4212 ab6573088b4a
child 4490 d45cde54d464
equal deleted inserted replaced
4484:d87989d91635 4485:5f99eb0b99f7
    11 
    11 
    12 from cubicweb import CW_SOFTWARE_ROOT as BASE
    12 from cubicweb import CW_SOFTWARE_ROOT as BASE
    13 from cubicweb.appobject import AppObject
    13 from cubicweb.appobject import AppObject
    14 from cubicweb.cwvreg import CubicWebVRegistry, UnknownProperty
    14 from cubicweb.cwvreg import CubicWebVRegistry, UnknownProperty
    15 from cubicweb.devtools import TestServerConfiguration
    15 from cubicweb.devtools import TestServerConfiguration
       
    16 from cubicweb.devtools.apptest import EnvBasedTC
    16 from cubicweb.interfaces import IMileStone
    17 from cubicweb.interfaces import IMileStone
    17 
    18 
    18 from cubes.card.entities import Card
    19 from cubes.card.entities import Card
    19 
    20 
    20 class YesSchema:
    21 class YesSchema:
    29         config = TestServerConfiguration('data')
    30         config = TestServerConfiguration('data')
    30         self.vreg = CubicWebVRegistry(config)
    31         self.vreg = CubicWebVRegistry(config)
    31         config.bootstrap_cubes()
    32         config.bootstrap_cubes()
    32         self.vreg.schema = config.load_schema()
    33         self.vreg.schema = config.load_schema()
    33 
    34 
       
    35     def test___selectors__compat(self):
       
    36         myselector1 = lambda *args: 1
       
    37         myselector2 = lambda *args: 1
       
    38         class AnAppObject(AppObject):
       
    39             __selectors__ = (myselector1, myselector2)
       
    40         AnAppObject.build___select__()
       
    41         self.assertEquals(AnAppObject.__select__(AnAppObject), 2)
       
    42 
    34     def test_load_interface_based_vojects(self):
    43     def test_load_interface_based_vojects(self):
    35         self.vreg.init_registration([WEBVIEWSDIR])
    44         self.vreg.init_registration([WEBVIEWSDIR])
    36         self.vreg.load_file(join(BASE, 'entities', '__init__.py'), 'cubicweb.entities.__init__')
    45         self.vreg.load_file(join(BASE, 'entities', '__init__.py'), 'cubicweb.entities.__init__')
    37         self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable')
    46         self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable')
    38         self.vreg.load_file(join(WEBVIEWSDIR, 'primary.py'), 'cubicweb.web.views.primary')
    47         self.vreg.load_file(join(WEBVIEWSDIR, 'primary.py'), 'cubicweb.web.views.primary')
    39         self.assertEquals(len(self.vreg['views']['primary']), 2)
    48         self.assertEquals(len(self.vreg['views']['primary']), 2)
    40         self.vreg.initialization_completed()
    49         self.vreg.initialization_completed()
    41         self.assertEquals(len(self.vreg['views']['primary']), 1)
    50         self.assertEquals(len(self.vreg['views']['primary']), 1)
    42 
       
    43     def test___selectors__compat(self):
       
    44         myselector1 = lambda *args: 1
       
    45         myselector2 = lambda *args: 1
       
    46         class AnAppObject(AppObject):
       
    47             __selectors__ = (myselector1, myselector2)
       
    48         AnAppObject.build___select__()
       
    49         self.assertEquals(AnAppObject.__select__(AnAppObject), 2)
       
    50 
       
    51     def test_properties(self):
       
    52         self.failIf('system.version.cubicweb' in self.vreg['propertydefs'])
       
    53         self.failUnless(self.vreg.property_info('system.version.cubicweb'))
       
    54         self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')
       
    55 
    51 
    56     def test_load_subinterface_based_appobjects(self):
    52     def test_load_subinterface_based_appobjects(self):
    57         self.vreg.reset()
    53         self.vreg.reset()
    58         self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
    54         self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
    59         # check progressbar was kicked
    55         # check progressbar was kicked
    66         self.vreg.register_objects([join(BASE, 'entities', '__init__.py'),
    62         self.vreg.register_objects([join(BASE, 'entities', '__init__.py'),
    67                                     join(BASE, 'web', 'views', 'iprogress.py')])
    63                                     join(BASE, 'web', 'views', 'iprogress.py')])
    68         # check progressbar isn't kicked
    64         # check progressbar isn't kicked
    69         self.assertEquals(len(self.vreg['views']['progressbar']), 1)
    65         self.assertEquals(len(self.vreg['views']['progressbar']), 1)
    70 
    66 
       
    67     def test_properties(self):
       
    68         self.failIf('system.version.cubicweb' in self.vreg['propertydefs'])
       
    69         self.failUnless(self.vreg.property_info('system.version.cubicweb'))
       
    70         self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')
       
    71 
       
    72 class CWVregTC(EnvBasedTC):
       
    73 
       
    74     def test_property_default_overriding(self):
       
    75         # see data/views.py
       
    76         from cubicweb.web.views.xmlrss import RSSIconBox
       
    77         self.assertEquals(self.vreg.property_info(RSSIconBox.propkey('visible'))['default'], True)
    71 
    78 
    72 if __name__ == '__main__':
    79 if __name__ == '__main__':
    73     unittest_main()
    80     unittest_main()