unittest_vregistry.py 3.6 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
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.cwvreg import CWRegistryStore, UnknownProperty
25
from cubicweb.devtools import TestServerConfiguration
26
from cubicweb.devtools.testlib import CubicWebTC
27
from cubicweb.view import EntityAdapter
Adrien Di Mascio's avatar
Adrien Di Mascio committed
28

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

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

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

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

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

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

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

54

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

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

80
81

class CWVregTC(CubicWebTC):
82
83
84
85

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

if __name__ == '__main__':
    unittest_main()