cubicweb/test/unittest_vregistry.py
changeset 11057 0b59724cb3f2
parent 9675 8aabfefc8a81
child 11269 73ac69970047
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
       
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 
       
    19 from logilab.common.testlib import unittest_main, TestCase
       
    20 
       
    21 from os.path import join
       
    22 
       
    23 from cubicweb import CW_SOFTWARE_ROOT as BASE
       
    24 from cubicweb.appobject import AppObject
       
    25 from cubicweb.cwvreg import CWRegistryStore, UnknownProperty
       
    26 from cubicweb.devtools import TestServerConfiguration
       
    27 from cubicweb.devtools.testlib import CubicWebTC
       
    28 from cubicweb.view import EntityAdapter
       
    29 
       
    30 from cubes.card.entities import Card
       
    31 
       
    32 class YesSchema:
       
    33     def __contains__(self, something):
       
    34         return True
       
    35 
       
    36 WEBVIEWSDIR = join(BASE, 'web', 'views')
       
    37 
       
    38 class VRegistryTC(TestCase):
       
    39 
       
    40     def setUp(self):
       
    41         config = TestServerConfiguration('data')
       
    42         self.vreg = CWRegistryStore(config)
       
    43         config.bootstrap_cubes()
       
    44         self.vreg.schema = config.load_schema()
       
    45 
       
    46     def test_load_interface_based_vojects(self):
       
    47         self.vreg.init_registration([WEBVIEWSDIR])
       
    48         self.vreg.load_file(join(BASE, 'entities', '__init__.py'), 'cubicweb.entities.__init__')
       
    49         self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable')
       
    50         self.vreg.load_file(join(WEBVIEWSDIR, 'primary.py'), 'cubicweb.web.views.primary')
       
    51         self.assertEqual(len(self.vreg['views']['primary']), 2)
       
    52         self.vreg.initialization_completed()
       
    53         self.assertEqual(len(self.vreg['views']['primary']), 1)
       
    54 
       
    55 
       
    56     def test_load_subinterface_based_appobjects(self):
       
    57         self.vreg.register_objects([join(BASE, 'web', 'views', 'idownloadable.py')])
       
    58         # check downloadlink was kicked
       
    59         self.assertFalse(self.vreg['views'].get('downloadlink'))
       
    60         # we've to emulate register_objects to add custom MyCard objects
       
    61         path = [join(BASE, 'entities', '__init__.py'),
       
    62                 join(BASE, 'entities', 'adapters.py'),
       
    63                 join(BASE, 'web', 'views', 'idownloadable.py')]
       
    64         filemods = self.vreg.init_registration(path, None)
       
    65         for filepath, modname in filemods:
       
    66             self.vreg.load_file(filepath, modname)
       
    67         class CardIDownloadableAdapter(EntityAdapter):
       
    68             __regid__ = 'IDownloadable'
       
    69         self.vreg._loadedmods[__name__] = {}
       
    70         self.vreg.register(CardIDownloadableAdapter)
       
    71         self.vreg.initialization_completed()
       
    72         # check progressbar isn't kicked
       
    73         self.assertEqual(len(self.vreg['views']['downloadlink']), 1)
       
    74 
       
    75     def test_properties(self):
       
    76         self.vreg.reset()
       
    77         self.assertNotIn('system.version.cubicweb', self.vreg['propertydefs'])
       
    78         self.assertTrue(self.vreg.property_info('system.version.cubicweb'))
       
    79         self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')
       
    80 
       
    81 
       
    82 class CWVregTC(CubicWebTC):
       
    83 
       
    84     def test_property_default_overriding(self):
       
    85         # see data/views.py
       
    86         from cubicweb.web.views.xmlrss import RSSIconBox
       
    87         self.assertEqual(self.vreg.property_info(RSSIconBox._cwpropkey('visible'))['default'], True)
       
    88 
       
    89 if __name__ == '__main__':
       
    90     unittest_main()