[Zope3-checkins] CVS: Zope3/src/zope/app/container/tests - test_objectcopier.py:1.6

Sidnei da Silva sidnei@x3ng.com.br
Mon, 31 Mar 2003 09:49:11 -0500


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

Modified Files:
	test_objectcopier.py 
Log Message:
Refactored feature of getting a copy without children into separate adapters and interfaces. With tests :)

=== Zope3/src/zope/app/container/tests/test_objectcopier.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/container/tests/test_objectcopier.py:1.5	Sun Mar 30 11:22:32 2003
+++ Zope3/src/zope/app/container/tests/test_objectcopier.py	Mon Mar 31 09:48:40 2003
@@ -20,21 +20,24 @@
 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 import getAdapter, ComponentLookupError
 from zope.component.adapter import provideAdapter
 from zope.app.traversing import IObjectName
 from zope.app.traversing.adapters import ObjectName
-from zope.app.interfaces.copypastemove import IObjectCopier
+from zope.app.interfaces.copypastemove import IObjectCopier, INoChildrenObjectCopier
 from zope.app.interfaces.content.folder import IFolder
+from zope.app.interfaces.container import CopyException
+from zope.app.interfaces.container import IContainer
 from zope.app.interfaces.container import IPasteTarget
-from zope.app.interfaces.container import ICopySource
+from zope.app.interfaces.container import ICopySource, INoChildrenCopySource
 from zope.app.interfaces.container import IPasteNamesChooser
 from zope.app.container.copypastemove import PasteTarget
-from zope.app.container.copypastemove import CopySource
+from zope.app.container.copypastemove import CopySource, NoChildrenCopySource
 from zope.app.container.copypastemove import PasteNamesChooser
-from zope.app.copypastemove import ObjectCopier
+from zope.app.copypastemove import ObjectCopier, NoChildrenObjectCopier
 from zope.app.content.folder import Folder
 from zope.app.content.file import File
+from zope.app.container.sample import SampleContainer
 
 class ObjectCopierTest(PlacefulSetup, TestCase):
 
@@ -163,9 +166,65 @@
         copier.copyTo(target)
         self.failUnless('folder1' in target)
 
+class NoChildrenObjectCopierTest(PlacefulSetup, TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self)
+        PlacefulSetup.buildFolders(self)
+        provideAdapter(None, IObjectCopier, ObjectCopier)
+        provideAdapter(IFolder, INoChildrenObjectCopier, NoChildrenObjectCopier)
+        provideAdapter(IContainer, INoChildrenObjectCopier, NoChildrenObjectCopier)
+        provideAdapter(IFolder, IPasteTarget, PasteTarget)
+        provideAdapter(IFolder, ICopySource, CopySource)
+        provideAdapter(IFolder, INoChildrenCopySource, NoChildrenCopySource)
+        provideAdapter(IContainer, INoChildrenCopySource, NoChildrenCopySource)
+        provideAdapter(None, IObjectName, ObjectName)
+        provideAdapter(IFolder, IPasteNamesChooser, PasteNamesChooser)
+ 
+    def test_copytosame(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        folder1 = traverse(root, 'folder1')
+        copier = getAdapter(folder1, INoChildrenObjectCopier)
+        copier.copyTo(container, 'new_folder1')
+        new_folder1 = traverse(container, 'new_folder1')
+        self.assertEquals(len(new_folder1.keys()), 0)
+
+    def test_notavailforfile(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        self.assertRaises(ComponentLookupError, getAdapter, file, INoChildrenObjectCopier)
+
+    def test_copytoother(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        target = traverse(root, 'folder2')
+        folder1_1 = traverse(root, 'folder1/folder1_1')
+        copier = getAdapter(folder1_1, INoChildrenObjectCopier)
+        copier.copyTo(target, 'folder1_1')
+        new_folder1_1 = traverse(root, 'folder2/folder1_1')
+        self.assertEquals(len(new_folder1_1.keys()), 0)
+
+    def test_notavailforfile(self):
+        root = self.rootFolder
+        container = traverse(root, 'folder1')
+        container.setObject('file1', File())
+        file = traverse(root, 'folder1/file1')
+        self.assertRaises(ComponentLookupError, getAdapter, file, INoChildrenObjectCopier)
+
+    def test_doesntimplementclonewithoutchildren(self):
+        root = self.rootFolder
+        root.setObject('sample', SampleContainer())
+        folder = traverse(root, 'sample')
+        copier = getAdapter(folder, INoChildrenObjectCopier)
+        self.assertRaises(CopyException, copier.copyTo, root, 'new_sample')
+
 def test_suite():
     return TestSuite((
         makeSuite(ObjectCopierTest),
+        makeSuite(NoChildrenObjectCopierTest),
         ))
 
 if __name__=='__main__':