Commit 4c33b368 authored by sylvain.thenault@logilab.fr's avatar sylvain.thenault@logilab.fr
Browse files

test and fix interface based objects cleaning

--HG--
branch : tls-sprint
parent 29ba95ea7e7d
...@@ -105,7 +105,7 @@ class CubicWebRegistry(VRegistry): ...@@ -105,7 +105,7 @@ class CubicWebRegistry(VRegistry):
kwargs['clear'] = True kwargs['clear'] = True
super(CubicWebRegistry, self).register(obj, **kwargs) super(CubicWebRegistry, self).register(obj, **kwargs)
# XXX bw compat # XXX bw compat
ifaces = getattr(obj, 'accepts_interfaces', None) ifaces = use_interfaces(obj)
if ifaces: if ifaces:
self._needs_iface[obj] = frozenset(ifaces) self._needs_iface[obj] = frozenset(ifaces)
...@@ -122,12 +122,15 @@ class CubicWebRegistry(VRegistry): ...@@ -122,12 +122,15 @@ class CubicWebRegistry(VRegistry):
interfaces = set() interfaces = set()
for classes in self.get('etypes', {}).values(): for classes in self.get('etypes', {}).values():
for cls in classes: for cls in classes:
interfaces.update(cls.__implements__) for iface in cls.__implements__:
interfaces.update(expand_parent_classes(iface))
for obj, ifaces in self._needs_iface.items(): for obj, ifaces in self._needs_iface.items():
if not ifaces & interfaces: if not ifaces & interfaces:
self.debug('kicking vobject %s (unsupported interface)', obj) self.debug('kicking vobject %s (unsupported interface)', obj)
self.unregister(obj) self.unregister(obj)
def eid_rset(self, cursor, eid, etype=None): def eid_rset(self, cursor, eid, etype=None):
"""return a result set for the given eid without doing actual query """return a result set for the given eid without doing actual query
(we have the eid, we can suppose it exists and user has access to the (we have the eid, we can suppose it exists and user has access to the
......
...@@ -5,7 +5,9 @@ from os.path import join ...@@ -5,7 +5,9 @@ from os.path import join
from cubicweb import CW_SOFTWARE_ROOT as BASE from cubicweb import CW_SOFTWARE_ROOT as BASE
from cubicweb.vregistry import VObject from cubicweb.vregistry import VObject
from cubicweb.cwvreg import CubicWebRegistry, UnknownProperty from cubicweb.cwvreg import CubicWebRegistry, UnknownProperty
from cubicweb.cwconfig import CubicWebConfiguration from cubicweb.devtools import TestServerConfiguration
from cubicweb.entities.lib import Card
from cubicweb.interfaces import IMileStone
class YesSchema: class YesSchema:
def __contains__(self, something): def __contains__(self, something):
...@@ -14,9 +16,10 @@ class YesSchema: ...@@ -14,9 +16,10 @@ class YesSchema:
class VRegistryTC(TestCase): class VRegistryTC(TestCase):
def setUp(self): def setUp(self):
config = CubicWebConfiguration('data') config = TestServerConfiguration('data')
self.vreg = CubicWebRegistry(config) self.vreg = CubicWebRegistry(config)
self.vreg.schema = YesSchema() config.bootstrap_cubes()
self.vreg.schema = config.load_schema()
def test_load(self): def test_load(self):
self.vreg.load_file(join(BASE, 'web', 'views'), 'euser.py') self.vreg.load_file(join(BASE, 'web', 'views'), 'euser.py')
...@@ -45,6 +48,19 @@ class VRegistryTC(TestCase): ...@@ -45,6 +48,19 @@ class VRegistryTC(TestCase):
self.failIf('system.version.cubicweb' in self.vreg['propertydefs']) self.failIf('system.version.cubicweb' in self.vreg['propertydefs'])
self.failUnless(self.vreg.property_info('system.version.cubicweb')) self.failUnless(self.vreg.property_info('system.version.cubicweb'))
self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key') self.assertRaises(UnknownProperty, self.vreg.property_info, 'a.non.existent.key')
def test_load_subinterface_based_vobjects(self):
self.vreg.reset()
self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
# check progressbar was kicked
self.failIf(self.vreg['views'].get('progressbar'))
class MyCard(Card):
__implements__ = (IMileStone,)
self.vreg.reset()
self.vreg.register_vobject_class(MyCard)
self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
# check progressbar isn't kicked
self.assertEquals(len(self.vreg['views']['progressbar']), 1)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment