unittest_vregistry.py 3.68 KB
Newer Older
1
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
2
3
4
5
6
7
8
9
10
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
12
13
14
15
16
17
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
18

Adrien Di Mascio's avatar
Adrien Di Mascio committed
19
20
21
22
23
from logilab.common.testlib import unittest_main, TestCase

from os.path import join

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
Adrien Di Mascio's avatar
Adrien Di Mascio committed
29

sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
30
31
from cubes.card.entities import Card

Adrien Di Mascio's avatar
Adrien Di Mascio committed
32
33
34
class YesSchema:
    def __contains__(self, something):
        return True
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
35
36

WEBVIEWSDIR = join(BASE, 'web', 'views')
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
37

Adrien Di Mascio's avatar
Adrien Di Mascio committed
38
39
40
class VRegistryTC(TestCase):

    def setUp(self):
41
        config = TestServerConfiguration('data', __file__)
42
        self.vreg = CWRegistryStore(config)
43
44
        config.bootstrap_cubes()
        self.vreg.schema = config.load_schema()
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
45

Adrien Di Mascio's avatar
Adrien Di Mascio committed
46
    def test_load_interface_based_vojects(self):
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
47
        self.vreg.init_registration([WEBVIEWSDIR])
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
48
        self.vreg.load_file(join(BASE, 'entities', '__init__.py'), 'cubicweb.entities.__init__')
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
49
        self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable')
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
50
        self.vreg.load_file(join(WEBVIEWSDIR, 'primary.py'), 'cubicweb.web.views.primary')
51
        self.assertEqual(len(self.vreg['views']['primary']), 2)
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
52
        self.vreg.initialization_completed()
53
        self.assertEqual(len(self.vreg['views']['primary']), 1)
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
54

55

56
    def test_load_subinterface_based_appobjects(self):
57
58
59
        self.vreg.register_objects([join(BASE, 'web', 'views', 'idownloadable.py')])
        # check downloadlink was kicked
        self.assertFalse(self.vreg['views'].get('downloadlink'))
60
61
        # we've to emulate register_objects to add custom MyCard objects
        path = [join(BASE, 'entities', '__init__.py'),
62
                join(BASE, 'entities', 'adapters.py'),
63
                join(BASE, 'web', 'views', 'idownloadable.py')]
64
65
66
        filemods = self.vreg.init_registration(path, None)
        for filepath, modname in filemods:
            self.vreg.load_file(filepath, modname)
67
68
        class CardIDownloadableAdapter(EntityAdapter):
            __regid__ = 'IDownloadable'
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
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)
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
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
80
        self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')

81
82

class CWVregTC(CubicWebTC):
83
84
85
86

    def test_property_default_overriding(self):
        # see data/views.py
        from cubicweb.web.views.xmlrss import RSSIconBox
87
        self.assertEqual(self.vreg.property_info(RSSIconBox._cwpropkey('visible'))['default'], True)
Adrien Di Mascio's avatar
Adrien Di Mascio committed
88
89
90

if __name__ == '__main__':
    unittest_main()