test and fix interface based objects cleaning tls-sprint
authorsylvain.thenault@logilab.fr
Wed, 18 Feb 2009 13:40:34 +0100
branchtls-sprint
changeset 777 39695e98ba35
parent 776 29ba95ea7e7d
child 778 847db4c91061
test and fix interface based objects cleaning
cwvreg.py
test/unittest_vregistry.py
--- a/cwvreg.py	Wed Feb 18 13:40:05 2009 +0100
+++ b/cwvreg.py	Wed Feb 18 13:40:34 2009 +0100
@@ -105,7 +105,7 @@
             kwargs['clear'] = True
         super(CubicWebRegistry, self).register(obj, **kwargs)
         # XXX bw compat
-        ifaces = getattr(obj, 'accepts_interfaces', None)
+        ifaces = use_interfaces(obj)
         if ifaces:
             self._needs_iface[obj] = frozenset(ifaces)
         
@@ -122,12 +122,15 @@
             interfaces = set()
             for classes in self.get('etypes', {}).values():
                 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():
                 if not ifaces & interfaces:
                     self.debug('kicking vobject %s (unsupported interface)', obj)
                     self.unregister(obj)
-
+            
+        
+    
     def eid_rset(self, cursor, eid, etype=None):
         """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
--- a/test/unittest_vregistry.py	Wed Feb 18 13:40:05 2009 +0100
+++ b/test/unittest_vregistry.py	Wed Feb 18 13:40:34 2009 +0100
@@ -5,7 +5,9 @@
 from cubicweb import CW_SOFTWARE_ROOT as BASE
 from cubicweb.vregistry import VObject
 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:
     def __contains__(self, something):
@@ -14,9 +16,10 @@
 class VRegistryTC(TestCase):
 
     def setUp(self):
-        config = CubicWebConfiguration('data')
+        config = TestServerConfiguration('data')
         self.vreg = CubicWebRegistry(config)
-        self.vreg.schema = YesSchema()
+        config.bootstrap_cubes()
+        self.vreg.schema = config.load_schema()
 
     def test_load(self):
         self.vreg.load_file(join(BASE, 'web', 'views'), 'euser.py')
@@ -45,6 +48,19 @@
         self.failIf('system.version.cubicweb' in self.vreg['propertydefs'])
         self.failUnless(self.vreg.property_info('system.version.cubicweb'))
         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__':