[Zope3-checkins] CVS: Zope3/src/zope/app/browser/container/tests - test_contents.py:1.25

Jim Fulton jim at zope.com
Sun Sep 21 13:30:29 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/browser/container/tests
In directory cvs.zope.org:/tmp/cvs-serv12111/src/zope/app/browser/container/tests

Modified Files:
	test_contents.py 
Log Message:
Use __setitem__ rather than setObject to add items to containers.

No longer need source and target adapters for copy and move.

Updated to reflect that add and remove events extend move, not the
other way around.

Changed to reflect new naming conventions for copying.

Added additional setup code to the basic contents tests because
contents now needs to look at the clipboard to decide whether to
display a paste button.


=== Zope3/src/zope/app/browser/container/tests/test_contents.py 1.24 => 1.25 ===
--- Zope3/src/zope/app/browser/container/tests/test_contents.py:1.24	Sun Aug 17 02:05:39 2003
+++ Zope3/src/zope/app/browser/container/tests/test_contents.py	Sun Sep 21 13:30:29 2003
@@ -28,20 +28,13 @@
 from zope.app.traversing import traverse
 from zope.app.interfaces.copypastemove import IObjectMover
 from zope.app.interfaces.copypastemove import IObjectCopier
-from zope.app.interfaces.container import IPasteTarget
-from zope.app.interfaces.container import IMoveSource
-from zope.app.interfaces.container import ICopySource
-from zope.app.interfaces.container import IPasteNamesChooser
 
 from zope.app.copypastemove import ObjectMover
 from zope.app.copypastemove import ObjectCopier
-from zope.app.container.copypastemove import PasteTarget
-from zope.app.container.copypastemove import MoveSource
-from zope.app.container.copypastemove import CopySource
-from zope.app.container.copypastemove import PasteNamesChooser
 
 from zope.app.event.tests.placelesssetup import getEvents, clearEvents
-from zope.app.interfaces.event import IObjectRemovedEvent, IObjectModifiedEvent
+from zope.app.interfaces.event import IObjectModifiedEvent
+from zope.app.interfaces.container import IObjectRemovedEvent
 from zope.interface import Interface, implements
 from zope.proxy import removeAllProxies
 
@@ -52,8 +45,9 @@
 from zope.app.interfaces.services.principalannotation \
     import IPrincipalAnnotationService
 from zope.app.interfaces.annotation import IAnnotations
+from zope.app.container.contained import contained
 
-class BaseTestContentsBrowserView(PlacelessSetup):
+class BaseTestContentsBrowserView(PlacefulSetup):
     """Base class for testing browser contents.
 
     Subclasses need to define a method, '_TestView__newContext', that
@@ -64,16 +58,25 @@
     """
 
     def setUp(self):
-        PlacelessSetup.setUp(self)
+        PlacefulSetup.setUp(self)
+        PlacefulSetup.buildFolders(self)
+        provideAdapter(None, IObjectCopier, ObjectCopier)
         provideAdapter(None, IObjectMover, ObjectMover)
 
+        provideAdapter(IAnnotations, IPrincipalClipboard, PrincipalClipboard)
+        root_sm = getServiceManager(None)
+        svc = PrincipalAnnotationService()
+        root_sm.defineService("PrincipalAnnotation", \
+            IPrincipalAnnotationService)
+        root_sm.provideService("PrincipalAnnotation", svc)
+
     def testInfo(self):
         # Do we get the correct information back from ContainerContents?
         container = self._TestView__newContext()
         subcontainer = self._TestView__newContext()
-        container.setObject('subcontainer', subcontainer)
+        container['subcontainer'] = subcontainer
         document = Document()
-        container.setObject('document', document)
+        container['document'] = document
 
         fc = self._TestView__newView(container)
         info_list = fc.listContentInfo()
@@ -94,7 +97,7 @@
     def testInfoWDublinCore(self):
         container = self._TestView__newContext()
         document = Document()
-        container.setObject('document', document)
+        container['document'] = document
 
         from datetime import datetime
         from zope.app.interfaces.dublincore import IZopeDublinCore
@@ -124,40 +127,18 @@
     def testRemove(self):
         container = self._TestView__newContext()
         subcontainer = self._TestView__newContext()
-        container.setObject('subcontainer', subcontainer)
+        container['subcontainer'] = subcontainer
         document = Document()
-        container.setObject('document', document)
+        container['document'] = document
         document2 = Document()
-        container.setObject('document2', document2)
+        container['document2'] = document2
 
         fc = self._TestView__newView(container)
 
-        self.failIf(getEvents(IObjectRemovedEvent))
-        self.failUnless(
-            getEvents(IObjectModifiedEvent,
-                      filter =
-                      lambda event:
-                      removeAllProxies(event.object) == container)
-           )
-        clearEvents()
-
         fc.request.form.update({'ids': ['document2']})
 
         fc.removeObjects()
 
-        self.failUnless(
-            getEvents(IObjectRemovedEvent,
-                      filter =
-                      lambda event:
-                      removeAllProxies(event.object) == document2)
-           )
-        self.failUnless(
-            getEvents(IObjectModifiedEvent,
-                      filter =
-                      lambda event:
-                      removeAllProxies(event.object) == container)
-           )
-
         info_list = fc.listContentInfo()
 
         self.assertEquals(len(info_list), 2)
@@ -191,10 +172,6 @@
         PlacefulSetup.buildFolders(self)
         provideAdapter(None, IObjectCopier, ObjectCopier)
         provideAdapter(None, IObjectMover, ObjectMover)
-        provideAdapter(IContainer, IPasteTarget, PasteTarget)
-        provideAdapter(IContainer, IMoveSource, MoveSource)
-        provideAdapter(IContainer, ICopySource, CopySource)
-        provideAdapter(IContainer, IPasteNamesChooser, PasteNamesChooser)
 
         provideAdapter(IAnnotations, IPrincipalClipboard, PrincipalClipboard)
         root_sm = getServiceManager(None)
@@ -209,7 +186,7 @@
         ids=['document1', 'document2']
         for id in ids:
             document = Document()
-            container.setObject(id, document)
+            container[id] = document
         fc.request.form.update({'rename_ids': ids,
                                 'new_value': ['document1_1', 'document2_2']
                                 })
@@ -223,15 +200,15 @@
         ids=['document1', 'document2']
         for id in ids:
             document = Document()
-            container.setObject(id, document)
+            container[id] = document
 
         fc.request.form['ids'] = ids
         fc.copyObjects()
         fc.pasteObjects()
         self.failIf('document1' not in container)
         self.failIf('document2' not in container)
-        self.failIf('copy_of_document1' not in container)
-        self.failIf('copy_of_document2' not in container)
+        self.failIf('document1-2' not in container)
+        self.failIf('document2-2' not in container)
 
     def testCopyFolder(self):
         container = traverse(self.rootFolder, 'folder1')
@@ -241,7 +218,7 @@
         fc.copyObjects()
         fc.pasteObjects()
         self.failIf('folder1_1' not in container)
-        self.failIf('copy_of_folder1_1' not in container)
+        self.failIf('folder1_1-2' not in container)
 
     def testCopyFolder2(self):
         container = traverse(self.rootFolder, '/folder1/folder1_1')
@@ -251,7 +228,7 @@
         fc.copyObjects()
         fc.pasteObjects()
         self.failIf('folder1_1_1' not in container)
-        self.failIf('copy_of_folder1_1_1' not in container)
+        self.failIf('folder1_1_1-2' not in container)
 
     def testCopyFolder3(self):
         container = traverse(self.rootFolder, '/folder1/folder1_1')
@@ -271,7 +248,7 @@
         ids=['document1', 'document2']
         for id in ids:
             document = Document()
-            container.setObject(id, document)
+            container[id] = document
         fc.request.form['ids'] = ids
         fc.cutObjects()
         fc.pasteObjects()
@@ -319,16 +296,17 @@
 
     def _TestView__newContext(self):
         from zope.app.container.sample import SampleContainer
-        from zope.app.content.folder import RootFolder
-        from zope.app.context import ContextWrapper
-        root = RootFolder()
+        from zope.app.content.folder import rootFolder
+        root = rootFolder()
         container = SampleContainer()
-        return ContextWrapper(container, root, name='sample')
+        return contained(container, root, 'sample')
 
     def _TestView__newView(self, container):
         from zope.app.browser.container.contents import Contents
         from zope.publisher.browser import TestRequest
-        return Contents(container, TestRequest())
+        request = TestRequest()
+        request.setUser(Principal())
+        return Contents(container, request)
 
 def test_suite():
     return TestSuite((




More information about the Zope3-Checkins mailing list