[Zope3-checkins] CVS: Zope3/src/zope/app/container/tests - test_objectcopier.py:1.2 test_objectmover.py:1.2 test_containertraverser.py:1.4

Sidnei da Silva sidnei@x3ng.com.br
Tue, 11 Feb 2003 11:00:13 -0500


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

Modified Files:
	test_containertraverser.py 
Added Files:
	test_objectcopier.py test_objectmover.py 
Log Message:
Merging paris-copypasterename-branch. Not very fun :(

=== Zope3/src/zope/app/container/tests/test_objectcopier.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 11 11:00:13 2003
+++ Zope3/src/zope/app/container/tests/test_objectcopier.py	Tue Feb 11 10:59:42 2003
@@ -0,0 +1,132 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.app.traversing import traverse
+from zope.app.services.tests.placefulsetup import PlacefulSetup
+from zope.component import getAdapter
+from zope.component.adapter import provideAdapter
+from zope.app.traversing import IObjectName
+from zope.app.traversing.adapters import ObjectName
+from zope.app.interfaces.copy import IObjectCopier
+from zope.app.interfaces.content.folder import IFolder
+from zope.app.interfaces.container import IPasteTarget
+from zope.app.interfaces.container import ICopySource
+from zope.app.interfaces.container import IPasteNamesChooser
+from zope.app.container.copy import PasteTarget
+from zope.app.container.copy import CopySource
+from zope.app.container.copy import PasteNamesChooser
+from zope.app.copy import ObjectCopier
+from zope.app.content.folder import Folder
+from zope.app.content.file import File
+
+class ObjectCopierTest(PlacefulSetup, TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self)
+        PlacefulSetup.buildFolders(self)
+        provideAdapter(None, IObjectCopier, ObjectCopier)
+        provideAdapter(IFolder, IPasteTarget, PasteTarget)
+        provideAdapter(IFolder, ICopySource, CopySource)
+        provideAdapter(None, IObjectName, ObjectName)
+        provideAdapter(IFolder, IPasteNamesChooser, PasteNamesChooser)
+ 
+    def test_copytosame(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        copier = getAdapter(file, IObjectCopier)
+        copier.copyTo(container, 'file1')
+        self.failUnless('file1' in container)
+        self.failUnless('copy_of_file1' in container)
+
+    def test_copytosamewithnewname(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        copier = getAdapter(file, IObjectCopier)
+        copier.copyTo(container, 'file2')
+        self.failUnless('file1' in container)
+        self.failUnless('file2' in container)
+
+    def test_copytoother(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        target = traverse(root, 'folder2')
+        file = traverse(root, 'folder1/file1')
+        copier = getAdapter(file, IObjectCopier)
+        copier.copyTo(target, 'file1')
+        self.failUnless('file1' in container)
+        self.failUnless('file1' in target)
+
+    def test_copytootherwithnewname(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        target = traverse(root, 'folder2')
+        file = traverse(root, 'folder1/file1')
+        copier = getAdapter(file, IObjectCopier)
+        copier.copyTo(target, 'file2')
+        self.failUnless('file1' in container)
+        self.failUnless('file2' in target)
+
+    def test_copytootherwithnamecollision(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        target = traverse(root, 'folder2')
+        target.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        copier = getAdapter(file, IObjectCopier)
+        copier.copyTo(target, 'file1')
+        # we do it twice, just to test auto-name generation
+        copier.copyTo(target, 'file1')
+        self.failUnless('file1' in container)
+        self.failUnless('file1' in target)
+        self.failUnless('copy_of_file1' in target)
+        self.failUnless('copy2_of_file1' in target)
+
+    def test_copyable(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        copier = getAdapter(file, IObjectCopier)
+        self.failUnless(copier.copyable())
+
+    def test_copyableTo(self):
+        #  A file should be copyable to a folder that has an
+        #  object with the same id.
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        copier = getAdapter(file, IObjectCopier)
+        self.failUnless(copier.copyableTo(container, 'file1'))
+        
+def test_suite():
+    return TestSuite((
+        makeSuite(ObjectCopierTest),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/container/tests/test_objectmover.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 11 11:00:13 2003
+++ Zope3/src/zope/app/container/tests/test_objectmover.py	Tue Feb 11 10:59:42 2003
@@ -0,0 +1,128 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.app.traversing import traverse
+from zope.app.services.tests.placefulsetup import PlacefulSetup
+from zope.component import getAdapter
+from zope.component.adapter import provideAdapter
+from zope.app.traversing import IObjectName
+from zope.app.traversing.adapters import ObjectName
+from zope.app.interfaces.copy import IObjectMover
+from zope.app.interfaces.content.folder import IFolder
+from zope.app.interfaces.container import IPasteTarget
+from zope.app.interfaces.container import IMoveSource
+from zope.app.interfaces.container import IPasteNamesChooser
+from zope.app.container.copy import PasteTarget
+from zope.app.container.copy import MoveSource
+from zope.app.container.copy import PasteNamesChooser
+from zope.app.copy import ObjectMover
+from zope.app.content.folder import Folder
+from zope.app.content.file import File
+
+class ObjectMoverTest(PlacefulSetup, TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self)
+        PlacefulSetup.buildFolders(self)
+        provideAdapter(None, IObjectMover, ObjectMover)
+        provideAdapter(IFolder, IPasteTarget, PasteTarget)
+        provideAdapter(IFolder, IMoveSource, MoveSource)
+        provideAdapter(None, IObjectName, ObjectName)
+        provideAdapter(IFolder, IPasteNamesChooser, PasteNamesChooser)
+ 
+    def test_movetosame(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        mover = getAdapter(file, IObjectMover)
+        mover.moveTo(container, 'file1')
+        self.failUnless('file1' in container)
+
+    def test_movetosamewithnewname(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        mover = getAdapter(file, IObjectMover)
+        mover.moveTo(container, 'file2')
+        self.failIf('file1' in container)
+        self.failUnless('file2' in container)
+
+    def test_movetoother(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        target = traverse(root, 'folder2')
+        file = traverse(root, 'folder1/file1')
+        mover = getAdapter(file, IObjectMover)
+        mover.moveTo(target, 'file1')
+        self.failIf('file1' in container)
+        self.failUnless('file1' in target)
+
+    def test_movetootherwithnewname(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        target = traverse(root, 'folder2')
+        file = traverse(root, 'folder1/file1')
+        mover = getAdapter(file, IObjectMover)
+        mover.moveTo(target, 'file2')
+        self.failIf('file1' in container)
+        self.failUnless('file2' in target)
+
+    def test_movetootherwithnamecollision(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        target = traverse(root, 'folder2')
+        target.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        mover = getAdapter(file, IObjectMover)
+        mover.moveTo(target, 'file1')
+        self.failIf('file1' in container)
+        self.failUnless('file1' in target)
+        self.failUnless('copy_of_file1' in target)
+
+    def test_moveable(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        mover = getAdapter(file, IObjectMover)
+        self.failUnless(mover.moveable())
+
+    def test_moveableTo(self):
+        #  A file should be moveable to a folder that has an
+        #  object with the same id.
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        mover = getAdapter(file, IObjectMover)
+        self.failUnless(mover.moveableTo(container, 'file1'))
+        
+def test_suite():
+    return TestSuite((
+        makeSuite(ObjectMoverTest),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/container/tests/test_containertraverser.py 1.3 => 1.4 ===