author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 21 Jul 2009 13:11:00 +0200 | |
branch | stable |
changeset 2405 | 443449336153 |
parent 1977 | 606923dff11b |
child 2650 | 18aec79ec3a3 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
7 |
""" |
0 | 8 |
from logilab.common.testlib import unittest_main, TestCase |
9 |
||
10 |
from os.path import join |
|
11 |
||
12 |
from cubicweb import CW_SOFTWARE_ROOT as BASE |
|
13 |
from cubicweb.vregistry import VObject |
|
14 |
from cubicweb.cwvreg import CubicWebRegistry, UnknownProperty |
|
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
15 |
from cubicweb.devtools import TestServerConfiguration |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
16 |
from cubicweb.interfaces import IMileStone |
0 | 17 |
|
1640 | 18 |
from cubes.card.entities import Card |
19 |
||
0 | 20 |
class YesSchema: |
21 |
def __contains__(self, something): |
|
22 |
return True |
|
1341 | 23 |
|
24 |
WEBVIEWSDIR = join(BASE, 'web', 'views') |
|
1640 | 25 |
|
0 | 26 |
class VRegistryTC(TestCase): |
27 |
||
28 |
def setUp(self): |
|
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
29 |
config = TestServerConfiguration('data') |
0 | 30 |
self.vreg = CubicWebRegistry(config) |
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
31 |
config.bootstrap_cubes() |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
32 |
self.vreg.schema = config.load_schema() |
1640 | 33 |
|
0 | 34 |
def test_load_interface_based_vojects(self): |
1341 | 35 |
self.vreg.init_registration([WEBVIEWSDIR]) |
1640 | 36 |
self.vreg.load_file(join(BASE, 'entities', '__init__.py'), 'cubicweb.entities.__init__') |
1341 | 37 |
self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable') |
1640 | 38 |
self.vreg.load_file(join(WEBVIEWSDIR, 'primary.py'), 'cubicweb.web.views.primary') |
0 | 39 |
self.assertEquals(len(self.vreg['views']['primary']), 2) |
1640 | 40 |
self.vreg.initialization_completed() |
41 |
self.assertEquals(len(self.vreg['views']['primary']), 1) |
|
42 |
||
740 | 43 |
def test___selectors__compat(self): |
0 | 44 |
myselector1 = lambda *args: 1 |
45 |
myselector2 = lambda *args: 1 |
|
46 |
class AnAppObject(VObject): |
|
47 |
__selectors__ = (myselector1, myselector2) |
|
740 | 48 |
AnAppObject.build___select__() |
49 |
self.assertEquals(AnAppObject.__select__(AnAppObject), 2) |
|
0 | 50 |
|
51 |
def test_properties(self): |
|
52 |
self.failIf('system.version.cubicweb' in self.vreg['propertydefs']) |
|
53 |
self.failUnless(self.vreg.property_info('system.version.cubicweb')) |
|
54 |
self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key') |
|
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
55 |
|
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
56 |
def test_load_subinterface_based_vobjects(self): |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
57 |
self.vreg.reset() |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
58 |
self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')]) |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
59 |
# check progressbar was kicked |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
60 |
self.failIf(self.vreg['views'].get('progressbar')) |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
61 |
class MyCard(Card): |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
62 |
__implements__ = (IMileStone,) |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
63 |
self.vreg.reset() |
1341 | 64 |
self.vreg._loadedmods[__name__] = {} |
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
65 |
self.vreg.register_vobject_class(MyCard) |
1640 | 66 |
self.vreg.register_objects([join(BASE, 'entities', '__init__.py'), |
67 |
join(BASE, 'web', 'views', 'iprogress.py')]) |
|
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
68 |
# check progressbar isn't kicked |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
69 |
self.assertEquals(len(self.vreg['views']['progressbar']), 1) |
1640 | 70 |
|
0 | 71 |
|
72 |
if __name__ == '__main__': |
|
73 |
unittest_main() |