[CMF-checkins] SVN: CMF/branches/2.0/C - fixed
IndexableObjectWrapper's __providedBy__ to allow the use of adapters
Yvo Schubbe
y.2006_ at wcm-solutions.de
Sun Apr 2 17:13:42 EDT 2006
Log message for revision 66325:
- fixed IndexableObjectWrapper's __providedBy__ to allow the use of adapters
- added some basic IndexableObjectWrapper tests
Changed:
U CMF/branches/2.0/CHANGES.txt
U CMF/branches/2.0/CMFCore/CatalogTool.py
U CMF/branches/2.0/CMFCore/tests/test_CatalogTool.py
-=-
Modified: CMF/branches/2.0/CHANGES.txt
===================================================================
--- CMF/branches/2.0/CHANGES.txt 2006-04-02 21:13:25 UTC (rev 66324)
+++ CMF/branches/2.0/CHANGES.txt 2006-04-02 21:13:42 UTC (rev 66325)
@@ -1,3 +1,15 @@
+CMF 2.0.0 (unreleased)
+
+ Bug Fixes
+
+ - IndexableObjectWrapper: Fixed list of provided interfaces.
+ The interfaces declared for the wrapped object are no longer masked.
+
+ - CMFDefault: Removed CMF specific slots from five_template.
+ The CMF specific slots added in CMF 2.0.0-alpha have been removed again
+ from the five_template.
+
+
CMF 2.0.0-beta2 (2006/03/26)
Bug Fixes
@@ -5,8 +17,6 @@
- CMFDefault: Refactored slots in five_template and main_template.
main_template has now a new 'body' slot that wraps around 'header' and
'main' slot. main_template's 'header' slot is now empty by default.
- The CMF specific slots added in CMF 2.0.0-alpha have been removed again
- from the five_template.
- PortalFolder: Content IDs starting with '@@' are now disallowed.
These names are reserved for browser views.
Modified: CMF/branches/2.0/CMFCore/CatalogTool.py
===================================================================
--- CMF/branches/2.0/CMFCore/CatalogTool.py 2006-04-02 21:13:25 UTC (rev 66324)
+++ CMF/branches/2.0/CMFCore/CatalogTool.py 2006-04-02 21:13:42 UTC (rev 66325)
@@ -22,6 +22,10 @@
from Globals import InitializeClass
from Products.ZCatalog.ZCatalog import ZCatalog
from zope.interface import implements
+from zope.interface import providedBy
+from zope.interface.declarations import getObjectSpecification
+from zope.interface.declarations import ObjectSpecification
+from zope.interface.declarations import ObjectSpecificationDescriptor
from ActionProviderBase import ActionProviderBase
from interfaces import ICatalogTool
@@ -40,15 +44,34 @@
from utils import UniqueObject
-class IndexableObjectWrapper:
+class IndexableObjectSpecification(ObjectSpecificationDescriptor):
+ def __get__(self, inst, cls=None):
+ if inst is None:
+ return getObjectSpecification(cls)
+ else:
+ provided = providedBy(inst._IndexableObjectWrapper__ob)
+ cls = type(inst)
+ return ObjectSpecification(provided, cls)
+
+
+class IndexableObjectWrapper(object):
+
implements(IIndexableObjectWrapper)
__implements__ = z2IIndexableObjectWrapper
+ __providedBy__ = IndexableObjectSpecification()
def __init__(self, vars, ob):
self.__vars = vars
self.__ob = ob
+ def __str__(self):
+ try:
+ # __str__ is used to get the data of File objects
+ return self.__ob.__str__()
+ except AttributeError:
+ return object.__str__(self)
+
def __getattr__(self, name):
vars = self.__vars
if vars.has_key(name):
Modified: CMF/branches/2.0/CMFCore/tests/test_CatalogTool.py
===================================================================
--- CMF/branches/2.0/CMFCore/tests/test_CatalogTool.py 2006-04-02 21:13:25 UTC (rev 66324)
+++ CMF/branches/2.0/CMFCore/tests/test_CatalogTool.py 2006-04-02 21:13:42 UTC (rev 66325)
@@ -15,10 +15,8 @@
$Id$
"""
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
import Testing
-import Zope2
-Zope2.startup()
from AccessControl.SecurityManagement import newSecurityManager
from DateTime import DateTime
@@ -30,52 +28,93 @@
from Products.CMFCore.tests.base.testcase import SecurityTest
-class IndexableObjectWrapperTests(TestCase):
+class IndexableObjectWrapperTests(unittest.TestCase):
+ def _getTargetClass(self):
+ from Products.CMFCore.CatalogTool import IndexableObjectWrapper
+
+ return IndexableObjectWrapper
+
+ def _makeOne(self, *args, **kw):
+ return self._getTargetClass()(*args, **kw)
+
def test_z2interfaces(self):
from Interface.Verify import verifyClass
- from Products.CMFCore.CatalogTool import IndexableObjectWrapper
from Products.CMFCore.interfaces.portal_catalog \
import IndexableObjectWrapper as IIndexableObjectWrapper
- verifyClass(IIndexableObjectWrapper, IndexableObjectWrapper)
+ verifyClass(IIndexableObjectWrapper, self._getTargetClass())
def test_z3interfaces(self):
from zope.interface.verify import verifyClass
- from Products.CMFCore.CatalogTool import IndexableObjectWrapper
from Products.CMFCore.interfaces import IIndexableObjectWrapper
- verifyClass(IIndexableObjectWrapper, IndexableObjectWrapper)
+ verifyClass(IIndexableObjectWrapper, self._getTargetClass())
+ def test_allowedRolesAndUsers(self):
+ obj = DummyContent()
+ w = self._makeOne({}, obj)
+ self.assertEqual(w.allowedRolesAndUsers(), ['Manager'])
+ def test___str__(self):
+ obj = DummyContent('foo')
+ w = self._makeOne({}, obj)
+ self.assertEqual(str(w), str(obj))
+
+ def test_proxied_attributes(self):
+ obj = DummyContent('foo')
+ obj.title = 'Foo'
+ w = self._makeOne({}, obj)
+ self.assertEqual(w.getId(), 'foo')
+ self.assertEqual(w.Title(), 'Foo')
+
+ def test_vars(self):
+ obj = DummyContent()
+ w = self._makeOne({'bar': 1, 'baz': 2}, obj)
+ self.assertEqual(w.bar, 1)
+ self.assertEqual(w.baz, 2)
+
+ def test_provided(self):
+ from Products.CMFCore.interfaces import IContentish
+ from Products.CMFCore.interfaces import IIndexableObjectWrapper
+
+ obj = DummyContent()
+ w = self._makeOne({}, obj)
+ self.failUnless(IContentish.providedBy(w))
+ self.failUnless(IIndexableObjectWrapper.providedBy(w))
+
+
class CatalogToolTests(SecurityTest):
- def _makeOne(self, *args, **kw):
+ def _getTargetClass(self):
from Products.CMFCore.CatalogTool import CatalogTool
- return CatalogTool(*args, **kw)
+ return CatalogTool
+ def _makeOne(self, *args, **kw):
+ return self._getTargetClass()(*args, **kw)
+
def test_z2interfaces(self):
from Interface.Verify import verifyClass
- from Products.CMFCore.CatalogTool import CatalogTool
from Products.CMFCore.interfaces.portal_actions \
import ActionProvider as IActionProvider
from Products.CMFCore.interfaces.portal_catalog \
import portal_catalog as ICatalogTool
from Products.ZCatalog.IZCatalog import IZCatalog
- verifyClass(IActionProvider, CatalogTool)
- verifyClass(ICatalogTool, CatalogTool)
- verifyClass(IZCatalog, CatalogTool)
+ verifyClass(IActionProvider, self._getTargetClass())
+ verifyClass(ICatalogTool, self._getTargetClass())
+ verifyClass(IZCatalog, self._getTargetClass())
def test_z3interfaces(self):
from zope.interface.verify import verifyClass
- from Products.CMFCore.CatalogTool import CatalogTool
from Products.CMFCore.interfaces import IActionProvider
from Products.CMFCore.interfaces import ICatalogTool
+ from Products.ZCatalog.interfaces import IZCatalog
- verifyClass(IActionProvider, CatalogTool)
- verifyClass(ICatalogTool, CatalogTool)
+ verifyClass(IActionProvider, self._getTargetClass())
+ verifyClass(ICatalogTool, self._getTargetClass())
+ verifyClass(IZCatalog, self._getTargetClass())
def loginWithRoles(self, *roles):
user = UserWithRoles(*roles).__of__(self.root)
@@ -320,10 +359,10 @@
def test_suite():
- return TestSuite((
- makeSuite(IndexableObjectWrapperTests),
- makeSuite(CatalogToolTests),
+ return unittest.TestSuite((
+ unittest.makeSuite(IndexableObjectWrapperTests),
+ unittest.makeSuite(CatalogToolTests),
))
if __name__ == '__main__':
- main(defaultTest='test_suite')
+ unittest.main(defaultTest='test_suite')
More information about the CMF-checkins
mailing list