unittest_vregistry.py 3.57 KB
Newer Older
Sylvain Thénault's avatar
Sylvain Thénault committed
1
# copyright 2003-2016 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
from logilab.common.testlib import unittest_main, TestCase

from os.path import join

23
from cubicweb import CW_SOFTWARE_ROOT as BASE, devtools
24
from cubicweb.cwvreg import CWRegistryStore, UnknownProperty
25
from cubicweb.devtools.testlib import CubicWebTC
26
from cubicweb.entity import EntityAdapter
Adrien Di Mascio's avatar
Adrien Di Mascio committed
27

sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
28

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

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

Sylvain Thénault's avatar
Sylvain Thénault committed
35

Adrien Di Mascio's avatar
Adrien Di Mascio committed
36
37
38
class VRegistryTC(TestCase):

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

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

53

54
    def test_load_subinterface_based_appobjects(self):
55
56
57
        self.vreg.register_objects([join(BASE, 'web', 'views', 'idownloadable.py')])
        # check downloadlink was kicked
        self.assertFalse(self.vreg['views'].get('downloadlink'))
58
59
        # we've to emulate register_objects to add custom MyCard objects
        path = [join(BASE, 'entities', '__init__.py'),
60
                join(BASE, 'entities', 'adapters.py'),
61
                join(BASE, 'web', 'views', 'idownloadable.py')]
62
63
64
        filemods = self.vreg.init_registration(path, None)
        for filepath, modname in filemods:
            self.vreg.load_file(filepath, modname)
65
66
        class CardIDownloadableAdapter(EntityAdapter):
            __regid__ = 'IDownloadable'
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
67
        self.vreg._loadedmods[__name__] = {}
68
        self.vreg.register(CardIDownloadableAdapter)
69
        self.vreg.initialization_completed()
70
        # check progressbar isn't kicked
71
        self.assertEqual(len(self.vreg['views']['downloadlink']), 1)
sylvain.thenault@logilab.fr's avatar
sylvain.thenault@logilab.fr committed
72

73
    def test_properties(self):
74
        self.vreg.reset()
75
        self.assertNotIn('system.version.cubicweb', self.vreg['propertydefs'])
76
        self.assertTrue(self.vreg.property_info('system.version.cubicweb'))
77
78
        self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')

79
80

class CWVregTC(CubicWebTC):
81
82
83
84

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

if __name__ == '__main__':
    unittest_main()