author | Florent <florent@secondweb.fr> |
Fri, 17 Apr 2009 08:51:16 +0200 | |
branch | tls-sprint |
changeset 1386 | 8ba1f0d36c7e |
parent 1341 | 9502d02630bf |
child 1640 | 65b60f177eb1 |
permissions | -rw-r--r-- |
0 | 1 |
from logilab.common.testlib import unittest_main, TestCase |
2 |
||
3 |
from os.path import join |
|
4 |
||
5 |
from cubicweb import CW_SOFTWARE_ROOT as BASE |
|
6 |
from cubicweb.vregistry import VObject |
|
7 |
from cubicweb.cwvreg import CubicWebRegistry, UnknownProperty |
|
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
8 |
from cubicweb.devtools import TestServerConfiguration |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
9 |
from cubicweb.entities.lib import Card |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
10 |
from cubicweb.interfaces import IMileStone |
0 | 11 |
|
12 |
class YesSchema: |
|
13 |
def __contains__(self, something): |
|
14 |
return True |
|
1341 | 15 |
|
16 |
WEBVIEWSDIR = join(BASE, 'web', 'views') |
|
0 | 17 |
|
18 |
class VRegistryTC(TestCase): |
|
19 |
||
20 |
def setUp(self): |
|
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
21 |
config = TestServerConfiguration('data') |
0 | 22 |
self.vreg = CubicWebRegistry(config) |
777
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
23 |
config.bootstrap_cubes() |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
24 |
self.vreg.schema = config.load_schema() |
1341 | 25 |
|
0 | 26 |
def test_load(self): |
1341 | 27 |
self.vreg.init_registration([WEBVIEWSDIR]) |
28 |
self.vreg.load_file(join(WEBVIEWSDIR, 'euser.py'), 'cubicweb.web.views.euser') |
|
29 |
self.vreg.load_file(join(WEBVIEWSDIR, 'baseviews.py'), 'cubicweb.web.views.baseviews') |
|
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
30 |
fpvc = [v for v in self.vreg.registry_objects('views', 'primary') |
633 | 31 |
if v.__module__ == 'cubicweb.web.views.euser'][0] |
0 | 32 |
fpv = fpvc(None, None) |
33 |
# don't want a TypeError due to super call |
|
34 |
self.assertRaises(AttributeError, fpv.render_entity_attributes, None, None) |
|
35 |
||
36 |
def test_load_interface_based_vojects(self): |
|
1341 | 37 |
self.vreg.init_registration([WEBVIEWSDIR]) |
38 |
self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable') |
|
39 |
self.vreg.load_file(join(WEBVIEWSDIR, 'baseviews.py'), 'cubicweb.web.views.baseviews') |
|
0 | 40 |
# check loading baseviews after idownloadable isn't kicking interface based views |
41 |
self.assertEquals(len(self.vreg['views']['primary']), 2) |
|
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) |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
66 |
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
|
67 |
# check progressbar isn't kicked |
39695e98ba35
test and fix interface based objects cleaning
sylvain.thenault@logilab.fr
parents:
750
diff
changeset
|
68 |
self.assertEquals(len(self.vreg['views']['progressbar']), 1) |
0 | 69 |
|
70 |
||
71 |
if __name__ == '__main__': |
|
72 |
unittest_main() |