[Checkins] SVN: zope.app.container/trunk/src/zope/app/container/ Substitute zope.app.zapi by direct calls to its wrapped apis. See bug 219302. Also added a test for the CheckDependency function

Lorenzo Gil lgs at sicem.biz
Mon Apr 21 13:35:28 EDT 2008


Log message for revision 85553:
  Substitute zope.app.zapi by direct calls to its wrapped apis. See bug 219302. Also added a test for the CheckDependency function

Changed:
  U   zope.app.container/trunk/src/zope/app/container/browser/contents.py
  U   zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py
  U   zope.app.container/trunk/src/zope/app/container/dependency.py
  A   zope.app.container/trunk/src/zope/app/container/tests/test_dependency.py
  U   zope.app.container/trunk/src/zope/app/container/traversal.py

-=-
Modified: zope.app.container/trunk/src/zope/app/container/browser/contents.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/browser/contents.py	2008-04-21 17:20:08 UTC (rev 85552)
+++ zope.app.container/trunk/src/zope/app/container/browser/contents.py	2008-04-21 17:35:27 UTC (rev 85553)
@@ -19,6 +19,7 @@
 
 import urllib
 
+from zope.component import queryMultiAdapter
 from zope.event import notify
 from zope.exceptions.interfaces import UserError
 from zope.security.interfaces import Unauthorized
@@ -33,8 +34,8 @@
 from zope.copypastemove.interfaces import IContainerItemRenamer
 from zope.annotation.interfaces import IAnnotations
 from zope.lifecycleevent import ObjectModifiedEvent, Attributes
+from zope.traversing.api import getName, getPath, joinPath, traverse
 
-from zope.app import zapi
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 from zope.app.container.i18n import ZopeMessageFactory as _
 
@@ -158,7 +159,7 @@
         info['retitle'] = id == retitle_id
 
 
-        zmi_icon = zapi.queryMultiAdapter((obj, self.request), name='zmi_icon')
+        zmi_icon = queryMultiAdapter((obj, self.request), name='zmi_icon')
         if zmi_icon is None:
             info['icon'] = None
         else:
@@ -221,10 +222,10 @@
         dc = IDCDescriptiveProperties(item)
         dc.title = new
         notify(ObjectModifiedEvent(item, Attributes(IZopeDublinCore, 'title')))
-        
+
     def hasAdding(self):
         """Returns true if an adding view is available."""
-        adding = zapi.queryMultiAdapter((self.context, self.request), name="+")
+        adding = queryMultiAdapter((self.context, self.request), name="+")
         return (adding is not None)
 
     def addObject(self):
@@ -234,7 +235,7 @@
         else:
             new = request["new_value"]
 
-        adding = zapi.queryMultiAdapter((self.context, self.request), name="+")
+        adding = queryMultiAdapter((self.context, self.request), name="+")
         if adding is None:
             adding = Adding(self.context, request)
         else:
@@ -267,7 +268,7 @@
             self.error = _("You didn't specify any ids to copy.")
             return
 
-        container_path = zapi.getPath(self.context)
+        container_path = getPath(self.context)
 
         # For each item, check that it can be copied; if so, save the
         # path of the object for later copying when a destination has
@@ -289,7 +290,7 @@
                     self.error = _("Object '${name}' cannot be copied",
                                    mapping=m)
                 return
-            items.append(zapi.joinPath(container_path, id))
+            items.append(joinPath(container_path, id))
 
         # store the requested operation in the principal annotations:
         clipboard = getPrincipalClipboard(self.request)
@@ -304,7 +305,7 @@
             self.error = _("You didn't specify any ids to cut.")
             return
 
-        container_path = zapi.getPath(self.context)
+        container_path = getPath(self.context)
 
         # For each item, check that it can be moved; if so, save the
         # path of the object for later moving when a destination has
@@ -326,7 +327,7 @@
                     self.error = _("Object '${name}' cannot be moved",
                                    mapping=m)
                 return
-            items.append(zapi.joinPath(container_path, id))
+            items.append(joinPath(container_path, id))
 
         # store the requested operation in the principal annotations:
         clipboard = getPrincipalClipboard(self.request)
@@ -342,7 +343,7 @@
         items = clipboard.getContents()
         for item in items:
             try:
-                obj = zapi.traverse(target, item['target'])
+                obj = traverse(target, item['target'])
             except TraversalError:
                 pass
             else:
@@ -373,7 +374,7 @@
         for item in items:
             duplicated_id = False
             try:
-                obj = zapi.traverse(target, item['target'])
+                obj = traverse(target, item['target'])
             except TraversalError:
                 pass
             else:
@@ -394,7 +395,7 @@
                     raise
 
             if duplicated_id:
-                not_pasteable_ids.append(zapi.getName(obj))
+                not_pasteable_ids.append(getName(obj))
 
         if moved:
             # Clear the clipboard if we do a move, but not if we only do a copy
@@ -421,7 +422,7 @@
         items = clipboard.getContents()
         for item in items:
             try:
-                zapi.traverse(self.context, item['target'])
+                traverse(self.context, item['target'])
             except TraversalError:
                 pass
             else:

Modified: zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py	2008-04-21 17:20:08 UTC (rev 85552)
+++ zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py	2008-04-21 17:35:27 UTC (rev 85553)
@@ -28,11 +28,12 @@
 from zope.security.interfaces import ForbiddenAttribute
 from zope.testing.doctestunit import DocTestSuite
 from zope.exceptions.interfaces import UserError
+from zope.traversing.api import getParent
 from zope.traversing.browser import AbsoluteURL
+from zope.traversing.browser.absoluteurl import absoluteURL
 from zope.traversing.browser.interfaces import IAbsoluteURL
 from zope.traversing.interfaces import IContainmentRoot
 
-from zope.app import zapi
 from zope.app.testing import ztapi
 from zope.app.testing.placelesssetup import PlacelessSetup, setUp, tearDown
 from zope.app.publisher.interfaces.browser import AddMenu
@@ -83,7 +84,7 @@
         if IContainmentRoot.providedBy(self.context):
             return ''
         name = self.context.__name__
-        url = zapi.absoluteURL(zapi.getParent(self.context), self.request)
+        url = absoluteURL(getParent(self.context), self.request)
         url += '/' + name
         return url
 

Modified: zope.app.container/trunk/src/zope/app/container/dependency.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/dependency.py	2008-04-21 17:20:08 UTC (rev 85552)
+++ zope.app.container/trunk/src/zope/app/container/dependency.py	2008-04-21 17:35:27 UTC (rev 85553)
@@ -20,10 +20,10 @@
 """
 __docformat__ = 'restructuredtext'
 
-from zope.app import zapi
 from zope.i18nmessageid import Message
 from zope.app.container.i18n import ZopeMessageFactory as _
 from zope.app.dependable.interfaces import IDependable, DependencyError
+from zope.traversing.api import getPath
 
 exception_msg = _("""
 Removal of object (${object}) which has dependents (${dependents})
@@ -39,7 +39,7 @@
         dependents = dependency.dependents()
         if dependents:
             mapping = {
-                "object": zapi.getPath(object),
+                "object": getPath(object),
                 "dependents": ", ".join(dependents)
                 }
             raise DependencyError(Message(exception_msg, mapping=mapping))

Added: zope.app.container/trunk/src/zope/app/container/tests/test_dependency.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/tests/test_dependency.py	                        (rev 0)
+++ zope.app.container/trunk/src/zope/app/container/tests/test_dependency.py	2008-04-21 17:35:27 UTC (rev 85553)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Test the CheckDependency event subscriber.
+
+$Id$
+"""
+import unittest
+
+from zope.interface import implements
+from zope.app.dependable.interfaces import IDependable, DependencyError
+from zope.app.container.contained import ObjectRemovedEvent
+from zope.app.container.dependency import CheckDependency
+from zope.traversing.interfaces import IPhysicallyLocatable
+
+class DummyObject(object):
+
+    implements(IDependable, IPhysicallyLocatable)
+
+    def dependents(self):
+        return ['dependency1', 'dependency2']
+
+    def getPath(self):
+        return '/dummy-object'
+
+
+class Test(unittest.TestCase):
+
+    def testCheckDependency(self):
+        obj = DummyObject()
+        parent = object()
+        event = ObjectRemovedEvent(obj, parent, 'oldName')
+        self.assertRaises(DependencyError, CheckDependency, event)
+
+
+def test_suite():
+    return unittest.TestSuite((
+            unittest.makeSuite(Test),
+            ))
+
+if __name__=='__main__':
+    unittest.main()


Property changes on: zope.app.container/trunk/src/zope/app/container/tests/test_dependency.py
___________________________________________________________________
Name: svn:keyworks
   + Id

Modified: zope.app.container/trunk/src/zope/app/container/traversal.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/traversal.py	2008-04-21 17:20:08 UTC (rev 85552)
+++ zope.app.container/trunk/src/zope/app/container/traversal.py	2008-04-21 17:35:27 UTC (rev 85553)
@@ -24,9 +24,9 @@
 from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
 from zope.publisher.interfaces import NotFound
 
-from zope.app import zapi
 from zope.app.container.interfaces import ISimpleReadContainer, IItemContainer
 from zope.app.container.interfaces import IReadContainer
+from zope.app.publisher.browser import getDefaultViewName
 
 # Note that the next two classes are included here because they
 # can be used for multiple view types.
@@ -55,7 +55,7 @@
 
     def browserDefault(self, request):
         """See zope.publisher.browser.interfaces.IBrowserPublisher"""
-        view_name = zapi.getDefaultViewName(self.context, request)
+        view_name = getDefaultViewName(self.context, request)
         view_uri = "@@%s" %view_name
         return self.context, (view_uri,)
 



More information about the Checkins mailing list