test/unittest_vregistry.py
branchtls-sprint
changeset 1341 9502d02630bf
parent 777 39695e98ba35
child 1640 65b60f177eb1
equal deleted inserted replaced
1340:12e46a39f3f2 1341:9502d02630bf
    10 from cubicweb.interfaces import IMileStone
    10 from cubicweb.interfaces import IMileStone
    11 
    11 
    12 class YesSchema:
    12 class YesSchema:
    13     def __contains__(self, something):
    13     def __contains__(self, something):
    14         return True
    14         return True
       
    15 
       
    16 WEBVIEWSDIR = join(BASE, 'web', 'views')
    15     
    17     
    16 class VRegistryTC(TestCase):
    18 class VRegistryTC(TestCase):
    17 
    19 
    18     def setUp(self):
    20     def setUp(self):
    19         config = TestServerConfiguration('data')
    21         config = TestServerConfiguration('data')
    20         self.vreg = CubicWebRegistry(config)
    22         self.vreg = CubicWebRegistry(config)
    21         config.bootstrap_cubes()
    23         config.bootstrap_cubes()
    22         self.vreg.schema = config.load_schema()
    24         self.vreg.schema = config.load_schema()
    23 
    25         
    24     def test_load(self):
    26     def test_load(self):
    25         self.vreg.load_file(join(BASE, 'web', 'views'), 'euser.py')
    27         self.vreg.init_registration([WEBVIEWSDIR])
    26         self.vreg.load_file(join(BASE, 'web', 'views'), 'baseviews.py')
    28         self.vreg.load_file(join(WEBVIEWSDIR, 'euser.py'), 'cubicweb.web.views.euser')
       
    29         self.vreg.load_file(join(WEBVIEWSDIR, 'baseviews.py'), 'cubicweb.web.views.baseviews')
    27         fpvc = [v for v in self.vreg.registry_objects('views', 'primary')
    30         fpvc = [v for v in self.vreg.registry_objects('views', 'primary')
    28                if v.__module__ == 'cubicweb.web.views.euser'][0]
    31                if v.__module__ == 'cubicweb.web.views.euser'][0]
    29         fpv = fpvc(None, None)
    32         fpv = fpvc(None, None)
    30         # don't want a TypeError due to super call
    33         # don't want a TypeError due to super call
    31         self.assertRaises(AttributeError, fpv.render_entity_attributes, None, None)
    34         self.assertRaises(AttributeError, fpv.render_entity_attributes, None, None)
    32 
    35 
    33     def test_load_interface_based_vojects(self):
    36     def test_load_interface_based_vojects(self):
    34         self.vreg.load_file(join(BASE, 'web', 'views'), 'idownloadable.py')
    37         self.vreg.init_registration([WEBVIEWSDIR])
    35         self.vreg.load_file(join(BASE, 'web', 'views'), 'baseviews.py')
    38         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')
    36         # check loading baseviews after idownloadable isn't kicking interface based views
    40         # check loading baseviews after idownloadable isn't kicking interface based views
    37         self.assertEquals(len(self.vreg['views']['primary']), 2)
    41         self.assertEquals(len(self.vreg['views']['primary']), 2)
    38                               
    42                               
    39     def test___selectors__compat(self):
    43     def test___selectors__compat(self):
    40         myselector1 = lambda *args: 1
    44         myselector1 = lambda *args: 1
    55         # check progressbar was kicked
    59         # check progressbar was kicked
    56         self.failIf(self.vreg['views'].get('progressbar'))
    60         self.failIf(self.vreg['views'].get('progressbar'))
    57         class MyCard(Card):
    61         class MyCard(Card):
    58             __implements__ = (IMileStone,)
    62             __implements__ = (IMileStone,)
    59         self.vreg.reset()
    63         self.vreg.reset()
       
    64         self.vreg._loadedmods[__name__] = {}
    60         self.vreg.register_vobject_class(MyCard)
    65         self.vreg.register_vobject_class(MyCard)
    61         self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
    66         self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
    62         # check progressbar isn't kicked
    67         # check progressbar isn't kicked
    63         self.assertEquals(len(self.vreg['views']['progressbar']), 1)
    68         self.assertEquals(len(self.vreg['views']['progressbar']), 1)
    64         
    69