SVN: CMF/branches/2.0/C Issue 445: Work around possible bogus alias left by '_guessMethodAliases'.

Tres Seaver <[email protected]>
Newsgroups gmane.comp.web.zope.cmf.cvs
Message-ID <[email protected]>
Log message for revision 69190:
  Issue 445:  Work around possible bogus alias left by '_guessMethodAliases'.

Changed:
  U   CMF/branches/2.0/CHANGES.txt
  U   CMF/branches/2.0/CMFCore/PortalContent.py
  U   CMF/branches/2.0/CMFCore/tests/base/dummy.py
  U   CMF/branches/2.0/CMFCore/tests/test_PortalContent.py

-=-
Modified: CMF/branches/2.0/CHANGES.txt
===================================================================
--- CMF/branches/2.0/CHANGES.txt	2006-07-18 18:48:28 UTC (rev 69189)
+++ CMF/branches/2.0/CHANGES.txt	2006-07-18 18:48:40 UTC (rev 69190)
@@ -2,9 +2,13 @@
 
   Bug Fixes
 
-    - Forward-ported fix for DCWorkflow global actions missing IDs
-      (http://www.zope.org/Collectors/CMF/308).
+    - CMFCore.PortalContent:  '_guessAliases' may leave type information
+      with a default alias of '(Default)';  work around that case.
+      (http://www.zope.org/Collectors/CMF/445)
 
+    - Forward-ported fix for DCWorkflow global actions missing IDs.
+      (http://www.zope.org/Collectors/CMF/308)
+
     - CMFCore Expression: Fixed 'request' provided by expression contexts.
       'request' was not set correctly if 'object' is not specified.
 

Modified: CMF/branches/2.0/CMFCore/PortalContent.py
===================================================================
--- CMF/branches/2.0/CMFCore/PortalContent.py	2006-07-18 18:48:28 UTC (rev 69189)
+++ CMF/branches/2.0/CMFCore/PortalContent.py	2006-07-18 18:48:40 UTC (rev 69190)
@@ -95,7 +95,7 @@
         """
         ti = self.getTypeInfo()
         method_id = ti and ti.queryMethodID('(Default)', context=self)
-        if method_id:
+        if method_id and method_id!='(Default)':
             method = getattr(self, method_id)
             if getattr(aq_base(method), 'isDocTemp', 0):
                 return method(self, self.REQUEST, self.REQUEST['RESPONSE'])

Modified: CMF/branches/2.0/CMFCore/tests/base/dummy.py
===================================================================
--- CMF/branches/2.0/CMFCore/tests/base/dummy.py	2006-07-18 18:48:28 UTC (rev 69189)
+++ CMF/branches/2.0/CMFCore/tests/base/dummy.py	2006-07-18 18:48:40 UTC (rev 69190)
@@ -88,6 +88,31 @@
         return True
 
 
+    def listActions(self, info=None, object=None):
+        rs = []
+        for k,v in self._actions.items():
+           rs.append( DummyAction( k,v ) )
+        return rs
+
+class DummyAction:
+
+    def __init__( self, id, target, permissions=() ):
+        self._id = id
+        self.target = target
+        self.permissions = permissions
+
+    def getId( self ):
+        return self._id
+
+    # can this be right? e.g. utils._getViewFor calls action
+    # attribute directly, which is not part of API but no other way
+    # to do it...
+    def action( self, context ):
+        return self.target
+
+    def getPermissions( self ):
+        return self.permissions
+
 class DummyContent( PortalContent, Item ):
     """
     A Dummy piece of PortalContent

Modified: CMF/branches/2.0/CMFCore/tests/test_PortalContent.py
===================================================================
--- CMF/branches/2.0/CMFCore/tests/test_PortalContent.py	2006-07-18 18:48:28 UTC (rev 69189)
+++ CMF/branches/2.0/CMFCore/tests/test_PortalContent.py	2006-07-18 18:48:40 UTC (rev 69190)
@@ -20,12 +20,15 @@
 
 from AccessControl.SecurityManagement import newSecurityManager
 from Acquisition import aq_base
+from OFS.Folder import Folder
 
+from Products.CMFCore.tests.base.dummy import DummyContent
+from Products.CMFCore.tests.base.dummy import DummyObject
 from Products.CMFCore.tests.base.dummy import DummySite
+from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFCore.tests.base.dummy import DummyUserFolder
 from Products.CMFCore.tests.base.testcase import SecurityRequestTest
 
-
 class PortalContentTests(unittest.TestCase):
 
     def test_z2interfaces(self):
@@ -48,7 +51,43 @@
         verifyClass(IContentish, PortalContent)
         verifyClass(IDynamicType, PortalContent)
 
+    def _setupCallTests(self, aliases):
+        # root
+        root = Folder( 'root' )
 
+        # set up dummy type info with problematic double-default alias
+        root._setObject( 'portal_types', DummyTool() )
+        root.portal_types.view_actions = aliases
+
+        # dummy content and skin
+        root._setObject( 'dummycontent', DummyContent() )
+        root._setObject( 'dummy_view', DummyObject() )
+        return root.dummycontent
+
+    def test_DoubleDefaultAlias(self):
+        test_aliases = ( ('(Default)', '(Default)'),
+                         ('view', 'dummy_view'),
+                       )
+        ob = self._setupCallTests(test_aliases)
+        # in unfixed version fail here with AttributeError
+        # can end up with this arrangement using _getAliases though
+        # in fixed version, falls through to _getViewFor, which is BBB
+        self.assertEqual( ob(), 'dummy' )
+
+    def test_BlankDefaultAlias(self):
+        test_aliases = ( ('(Default)', ''),
+                         ('view', 'dummy_view'),
+                       )
+        ob = self._setupCallTests(test_aliases)
+        # blank default is BBB
+        self.assertEqual( ob(), 'dummy' )
+
+    def test_SpecificAlias(self):
+        test_aliases = ( ('(Default)', 'dummy_view'),
+                       )
+        ob = self._setupCallTests(test_aliases)
+        self.assertEqual( ob(), 'dummy' )
+
 class TestContentCopyPaste(SecurityRequestTest):
 
     # Tests related to http://www.zope.org/Collectors/CMF/205
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.