[CMF-checkins] SVN: CMF/trunk/CMFDefault/ - fixed interface used for uid handler lookup

Yvo Schubbe y.2007- at wcm-solutions.de
Sun Mar 11 09:43:39 EDT 2007


Log message for revision 73140:
  - fixed interface used for uid handler lookup
  - removed unconditional CMFUid dependency
  - modernized related tests

Changed:
  U   CMF/trunk/CMFDefault/Favorite.py
  U   CMF/trunk/CMFDefault/tests/test_Portal.py

-=-
Modified: CMF/trunk/CMFDefault/Favorite.py
===================================================================
--- CMF/trunk/CMFDefault/Favorite.py	2007-03-11 13:43:19 UTC (rev 73139)
+++ CMF/trunk/CMFDefault/Favorite.py	2007-03-11 13:43:38 UTC (rev 73140)
@@ -17,10 +17,9 @@
 
 import urlparse
 
-from Globals import InitializeClass
 from AccessControl import ClassSecurityInfo
 from Acquisition import aq_base
-
+from Globals import InitializeClass
 from zope.app.container.interfaces import IObjectAddedEvent
 from zope.component import adapter
 from zope.component import getUtility
@@ -30,7 +29,10 @@
 
 from Products.CMFCore.interfaces import ISiteRoot
 from Products.CMFCore.interfaces import IURLTool
-from Products.CMFUid.interfaces import IUniqueIdAnnotationManagement
+try:
+    from Products.CMFUid.interfaces import IUniqueIdHandler
+except ImportError:
+    IUniqueIdHandler = None
 
 from DublinCore import DefaultDublinCoreImpl
 from interfaces import IFavorite
@@ -73,8 +75,8 @@
         the unique id handler tool is available.
         """
         # check for unique id handler tool
-        handler = queryUtility(IUniqueIdAnnotationManagement)
-        if handler is None or not hasattr(handler, 'register'):
+        handler = IUniqueIdHandler and queryUtility(IUniqueIdHandler)
+        if handler is None:
             return
 
         obj = getUtility(ISiteRoot).restrictedTraverse(self.remote_url)
@@ -85,15 +87,15 @@
         the unique id handler tool is available.
         """
         # check for unique id handler tool
-        handler = queryUtility(IUniqueIdAnnotationManagement)
-        if handler is None or not hasattr(handler, 'queryObject'):
+        handler = IUniqueIdHandler and queryUtility(IUniqueIdHandler)
+        if handler is None:
             return
-        
+
         # check for remote uid info on object
         uid = getattr(aq_base(self), 'remote_uid', None)
         if uid is None:
             return
-        
+
         return handler.queryObject(uid, None)
 
     security.declareProtected(View, 'getRemoteUrl')
@@ -110,7 +112,7 @@
             if url != remote_url:
                 self.edit(url)
             return url
-        
+
         return remote_url
 
     def _getRemoteUrlTheOldWay(self):

Modified: CMF/trunk/CMFDefault/tests/test_Portal.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_Portal.py	2007-03-11 13:43:19 UTC (rev 73139)
+++ CMF/trunk/CMFDefault/tests/test_Portal.py	2007-03-11 13:43:38 UTC (rev 73140)
@@ -22,8 +22,16 @@
 from AccessControl.User import UnrestrictedUser
 from Acquisition import aq_base
 from zope.app.component.hooks import setSite
+from zope.component import getUtility
+from zope.component import queryUtility
 
+from Products.CMFCore.interfaces import ICatalogTool
+from Products.CMFCore.interfaces import ITypesTool
 from Products.CMFDefault.testing import FunctionalLayer
+try:
+    from Products.CMFUid.interfaces import IUniqueIdHandler
+except ImportError:
+    IUniqueIdHandler = None
 
 
 class CMFSiteTests(ZopeTestCase.FunctionalTestCase):
@@ -45,17 +53,17 @@
         setSite(self.app.site)
 
     def test_new( self ):
-        site = self.app.site
+        catalog = getUtility(ICatalogTool)
 
-        self.assertEqual( len( site.portal_catalog ), 0 )
+        self.assertEqual(len(catalog), 0)
 
     def test_MetadataCataloguing( self ):
         site = self.app.site
-        catalog = site.portal_catalog
-        site.portal_membership.memberareaCreationFlag = 0
-        uid_handler = getattr(site, 'portal_uidhandler', None)
+        catalog = getUtility(ICatalogTool)
+        ttool = getUtility(ITypesTool)
+        uid_handler = IUniqueIdHandler and queryUtility(IUniqueIdHandler)
 
-        portal_types = [ x for x in site.portal_types.listContentTypes()
+        portal_types = [ x for x in ttool.listContentTypes()
                            if x not in ( 'Discussion Item'
                                        , 'CMF BTree Folder'
                                        , 'Folder'
@@ -100,7 +108,7 @@
 
     def test_DocumentEditCataloguing( self ):
         site = self.app.site
-        catalog = site.portal_catalog
+        catalog = getUtility(ICatalogTool)
 
         doc = self._makeContent( site
                                , portal_type='Document'
@@ -118,7 +126,7 @@
 
     def test_ImageEditCataloguing( self ):
         site = self.app.site
-        catalog = site.portal_catalog
+        catalog = getUtility(ICatalogTool)
 
         doc = self._makeContent( site
                                , portal_type='Image'
@@ -134,7 +142,7 @@
 
     def test_FileEditCataloguing( self ):
         site = self.app.site
-        catalog = site.portal_catalog
+        catalog = getUtility(ICatalogTool)
 
         doc = self._makeContent( site
                                , portal_type='File'
@@ -150,7 +158,7 @@
 
     def test_LinkEditCataloguing( self ):
         site = self.app.site
-        catalog = site.portal_catalog
+        catalog = getUtility(ICatalogTool)
 
         doc = self._makeContent( site
                                , portal_type='Link'
@@ -166,7 +174,7 @@
 
     def test_NewsItemEditCataloguing( self ):
         site = self.app.site
-        catalog = site.portal_catalog
+        catalog = getUtility(ICatalogTool)
 
         doc = self._makeContent( site
                                , portal_type='News Item'



More information about the CMF-checkins mailing list