test/unittest_vregistry.py
changeset 0 b97547f5f1fa
child 631 99f5852f8604
equal deleted inserted replaced
-1:000000000000 0:b97547f5f1fa
       
     1 from logilab.common.testlib import unittest_main, TestCase
       
     2 
       
     3 from os.path import join
       
     4 
       
     5 from cubicweb import CW_SOFTWARE_ROOT as BASE
       
     6 from cubicweb.vregistry import VObject
       
     7 from cubicweb.cwvreg import CubicWebRegistry, UnknownProperty
       
     8 from cubicweb.cwconfig import CubicWebConfiguration
       
     9 
       
    10 class YesSchema:
       
    11     def __contains__(self, something):
       
    12         return True
       
    13     
       
    14 class VRegistryTC(TestCase):
       
    15 
       
    16     def setUp(self):
       
    17         config = CubicWebConfiguration('data')
       
    18         self.vreg = CubicWebRegistry(config)
       
    19         self.vreg.schema = YesSchema()
       
    20 
       
    21     def test_load(self):
       
    22         self.vreg.load_file(join(BASE, 'web', 'views'), 'euser.py')
       
    23         self.vreg.load_file(join(BASE, 'web', 'views'), 'baseviews.py')
       
    24         fpvc = [v for v in self.vreg.registry_objects('views', 'primary') if v.accepts[0] == 'EUser'][0]
       
    25         fpv = fpvc(None, None)
       
    26         # don't want a TypeError due to super call
       
    27         self.assertRaises(AttributeError, fpv.render_entity_attributes, None, None)
       
    28 
       
    29     def test_load_interface_based_vojects(self):
       
    30         self.vreg.load_file(join(BASE, 'web', 'views'), 'idownloadable.py')
       
    31         self.vreg.load_file(join(BASE, 'web', 'views'), 'baseviews.py')
       
    32         # check loading baseviews after idownloadable isn't kicking interface based views
       
    33         self.assertEquals(len(self.vreg['views']['primary']), 2)
       
    34                               
       
    35     def test_autoselectors(self):
       
    36         myselector1 = lambda *args: 1
       
    37         myselector2 = lambda *args: 1
       
    38         class AnAppObject(VObject):
       
    39             __selectors__ = (myselector1, myselector2)
       
    40         self.assertEquals(AnAppObject.__select__(), 2)
       
    41 
       
    42     def test_properties(self):
       
    43         self.failIf('system.version.cubicweb' in self.vreg['propertydefs'])
       
    44         self.failUnless(self.vreg.property_info('system.version.cubicweb'))
       
    45         self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')
       
    46         
       
    47 
       
    48 if __name__ == '__main__':
       
    49     unittest_main()