[Checkins] SVN: Products.CMFUid/trunk/Products/CMFUid/ - converted three more tools
Yvo Schubbe
y.2011 at wcm-solutions.de
Fri Sep 16 07:20:25 EST 2011
Log message for revision 122824:
- converted three more tools
Changed:
U Products.CMFUid/trunk/Products/CMFUid/CHANGES.txt
UU Products.CMFUid/trunk/Products/CMFUid/UniqueIdHandlerTool.py
U Products.CMFUid/trunk/Products/CMFUid/tests/test_uidhandling.py
-=-
Modified: Products.CMFUid/trunk/Products/CMFUid/CHANGES.txt
===================================================================
--- Products.CMFUid/trunk/Products/CMFUid/CHANGES.txt 2011-09-16 12:20:11 UTC (rev 122823)
+++ Products.CMFUid/trunk/Products/CMFUid/CHANGES.txt 2011-09-16 12:20:25 UTC (rev 122824)
@@ -4,6 +4,8 @@
2.3.0-alpha (unreleased)
------------------------
+- Made sure converted tools are used as utilities.
+
- Require at least Zope 2.13.4.
- Deal with deprecation warnings for Zope 2.13.
Modified: Products.CMFUid/trunk/Products/CMFUid/UniqueIdHandlerTool.py
===================================================================
--- Products.CMFUid/trunk/Products/CMFUid/UniqueIdHandlerTool.py 2011-09-16 12:20:11 UTC (rev 122823)
+++ Products.CMFUid/trunk/Products/CMFUid/UniqueIdHandlerTool.py 2011-09-16 12:20:25 UTC (rev 122824)
@@ -13,8 +13,6 @@
"""Unique Id Handler Tool
Provides support for accessing unique ids on content object.
-
-$Id$
"""
import logging
@@ -30,8 +28,8 @@
from zope.component import getUtility
from zope.interface import implements
+from Products.CMFCore.interfaces import ICatalogTool
from Products.CMFCore.permissions import ManagePortal
-from Products.CMFCore.utils import getToolByName
from Products.CMFCore.utils import UniqueObject
from Products.CMFUid.interfaces import IUniqueIdAnnotationManagement
from Products.CMFUid.interfaces import IUniqueIdBrainQuery
@@ -72,10 +70,8 @@
security = ClassSecurityInfo()
def _reindexObject(self, obj):
- # XXX: this method violates the rules for tools/utilities:
- # it depends on a non-utility tool
- catalog = getToolByName(self, 'portal_catalog')
- catalog.reindexObject(obj, idxs=[self.UID_ATTRIBUTE_NAME])
+ ctool = getUtility(ICatalogTool)
+ ctool.reindexObject(obj, idxs=[self.UID_ATTRIBUTE_NAME])
def _setUid(self, obj, uid):
"""Attaches a unique id to the object and does reindexing.
@@ -164,8 +160,6 @@
"""This helper method does the "hard work" of querying the catalog
and interpreting the results.
"""
- # XXX: this method violates the rules for tools/utilities:
- # it depends on a non-utility tool
if uid is None:
return default
@@ -173,8 +167,8 @@
generator = getUtility(IUniqueIdGenerator)
uid = generator.convert(uid)
- catalog = getToolByName(self, 'portal_catalog')
- searchMethod = getattr(catalog, searchMethodName)
+ ctool = getUtility(ICatalogTool)
+ searchMethod = getattr(ctool, searchMethodName)
result = searchMethod({self.UID_ATTRIBUTE_NAME: uid})
len_result = len(result)
Property changes on: Products.CMFUid/trunk/Products/CMFUid/UniqueIdHandlerTool.py
___________________________________________________________________
Deleted: svn:keywords
- Author Date Id Revision
Modified: Products.CMFUid/trunk/Products/CMFUid/tests/test_uidhandling.py
===================================================================
--- Products.CMFUid/trunk/Products/CMFUid/tests/test_uidhandling.py 2011-09-16 12:20:11 UTC (rev 122823)
+++ Products.CMFUid/trunk/Products/CMFUid/tests/test_uidhandling.py 2011-09-16 12:20:25 UTC (rev 122824)
@@ -20,12 +20,12 @@
from zope.interface.verify import verifyClass
from zope.testing.cleanup import cleanUp
+from Products.CMFCore.interfaces import ICatalogTool
from Products.CMFCore.tests.base.dummy import DummyContent
from Products.CMFCore.tests.base.dummy import DummyFolder
from Products.CMFCore.tests.base.testcase import SecurityTest
from Products.CMFUid.interfaces import IUniqueIdAnnotationManagement
from Products.CMFUid.interfaces import IUniqueIdGenerator
-from Products.CMFUid.interfaces import IUniqueIdHandler
class DummyUid:
@@ -56,24 +56,22 @@
import UniqueIdAnnotationTool
from Products.CMFUid.UniqueIdGeneratorTool \
import UniqueIdGeneratorTool
- SecurityTest.setUp(self)
- self.root._setObject('portal_catalog', CatalogTool())
- self.root._setObject('portal_uidgenerator', UniqueIdGeneratorTool())
- self.root._setObject('portal_uidannotation', UniqueIdAnnotationTool())
- self.root._setObject('portal_uidhandler', self._getTargetClass()())
- self.root._setObject('dummy', DummyContent(id='dummy'))
- self.root._setObject('dummy2', DummyContent(id='dummy2'))
+ SecurityTest.setUp(self)
+ self.app._setObject('portal_uidhandler', self._getTargetClass()())
+ self.app._setObject('dummy', DummyContent(id='dummy'))
+ self.app._setObject('dummy2', DummyContent(id='dummy2'))
sm = getSiteManager()
- sm.registerUtility( self.root.portal_uidannotation
- , IUniqueIdAnnotationManagement
- )
- sm.registerUtility(self.root.portal_uidgenerator, IUniqueIdGenerator)
+ self.ctool = CatalogTool().__of__(self.app)
+ sm.registerUtility(self.ctool, ICatalogTool)
+ sm.registerUtility(UniqueIdAnnotationTool(),
+ IUniqueIdAnnotationManagement)
+ sm.registerUtility(UniqueIdGeneratorTool(), IUniqueIdGenerator)
# Make sure we have our indices/columns
- uid_name = self.root.portal_uidhandler.UID_ATTRIBUTE_NAME
- self.root.portal_catalog.addIndex(uid_name, 'FieldIndex')
- self.root.portal_catalog.addColumn(uid_name)
+ uid_name = self.app.portal_uidhandler.UID_ATTRIBUTE_NAME
+ self.ctool.addIndex(uid_name, 'FieldIndex')
+ self.ctool.addColumn(uid_name)
def tearDown(self):
cleanUp()
@@ -220,7 +218,7 @@
# calling a getter returns one object and generates a log
# we can't capture. So let's ask the catalog directly.
- catalog = self.root.portal_catalog
+ catalog = self.ctool
result = catalog({handler.UID_ATTRIBUTE_NAME: uid1_reg})
self.assertEqual(len(result), 2)
@@ -250,7 +248,7 @@
def test_UidCataloging(self):
handler = self.root.portal_uidhandler
- catalog = self.root.portal_catalog
+ catalog = self.ctool
dummy = self.root.dummy
uid = handler.register(dummy)
@@ -259,7 +257,7 @@
def test_UidCatalogingDoesNotAcquireUid(self):
handler = self.root.portal_uidhandler
- catalog = self.root.portal_catalog
+ catalog = self.ctool
self.root._setObject('folder', DummyFolder('folder'))
folder = self.root.folder
@@ -276,7 +274,7 @@
def test_UidCatalogingDoesNotCatalogPortalRoot(self):
handler = self.root.portal_uidhandler
- catalog = self.root.portal_catalog
+ catalog = self.ctool
dummy = self.root.dummy
# mock the portal root, which has empty indexing attributes
More information about the checkins
mailing list