[Zope3-checkins] CVS: Zope3/src/zope/app/tests - test_clipboard.py:1.2

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


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

Added Files:
	test_clipboard.py 
Log Message:
Merging paris-copypasterename-branch. Not very fun :(

=== Zope3/src/zope/app/tests/test_clipboard.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 11 11:00:32 2003
+++ Zope3/src/zope/app/tests/test_clipboard.py	Tue Feb 11 11:00:00 2003
@@ -0,0 +1,99 @@
+from zope.app.services.tests.test_auth import AuthSetup
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.app.interfaces.copy import IPrincipalClipboard
+from zope.app.copy import PrincipalClipboard
+from zope.app.interfaces.services.auth import IUser
+from zope.component import getAdapter, getService, getServiceManager
+from zope.component.adapter import provideAdapter
+from zope.app.services.principalannotation \
+    import PrincipalAnnotationService
+from zope.app.interfaces.services.principalannotation \
+    import IPrincipalAnnotationService
+from zope.app.services.tests.placefulsetup \
+    import PlacefulSetup
+from zope.app.interfaces.annotation import IAnnotations
+ 
+class PrincipalClipboardTest(AuthSetup, PlacefulSetup, TestCase):
+    
+    def setUp(self):
+        AuthSetup.setUp(self)
+        PlacefulSetup.setUp(self)
+        self.buildFolders()
+
+        provideAdapter(IAnnotations, IPrincipalClipboard, PrincipalClipboard)
+        root_sm = getServiceManager(None)
+        svc = PrincipalAnnotationService()
+        root_sm.defineService("PrincipalAnnotation", \
+            IPrincipalAnnotationService) 
+        root_sm.provideService("PrincipalAnnotation", svc)
+        sm = getServiceManager(self.rootFolder)
+        sm.PrincipalAnnotation = svc
+        self.svc = getService(self.rootFolder, "PrincipalAnnotation")
+
+    def testAddItems(self):
+        auth = self._auth
+        user = auth.getPrincipalByLogin('srichter')
+
+        annotationsvc = getService(self, 'PrincipalAnnotation')
+        annotations = annotationsvc.getAnnotation(user)
+        clipboard = getAdapter(annotations, IPrincipalClipboard)
+        clipboard.addItems('move', ['bla', 'bla/foo', 'bla/bar'])
+        expected = ({'action':'move', 'target':'bla'}, 
+                    {'action':'move', 'target':'bla/foo'},
+                    {'action':'move', 'target':'bla/bar'})
+                    
+        self.failUnless(clipboard.getContents() == expected)
+        clipboard.addItems('copy', ['bla'])
+        expected = expected + ({'action':'copy', 'target':'bla'},) 
+        self.failUnless(clipboard.getContents() == expected)
+
+    def testSetContents(self):
+        auth = self._auth
+        user = auth.getPrincipalByLogin('srichter')
+
+        annotationsvc = getService(self, 'PrincipalAnnotation')
+        annotations = annotationsvc.getAnnotation(user)
+        clipboard = getAdapter(annotations, IPrincipalClipboard)
+
+        expected = ({'action':'move', 'target':'bla'}, 
+                    {'action':'move', 'target':'bla/foo'},
+                    {'action':'move', 'target':'bla/bar'})
+        clipboard.setContents(expected)
+        self.failUnless(clipboard.getContents() == expected)
+        clipboard.addItems('copy', ['bla'])
+        expected = expected + ({'action':'copy', 'target':'bla'},) 
+        self.failUnless(clipboard.getContents() == expected)
+
+    def testClearContents(self):
+        auth = self._auth
+        user = auth.getPrincipalByLogin('srichter')
+        annotationsvc = getService(self, 'PrincipalAnnotation')
+        annotations = annotationsvc.getAnnotation(user)
+        clipboard = getAdapter(annotations, IPrincipalClipboard)
+        clipboard.clearContents()
+        self.failUnless(clipboard.getContents() == ())
+
+def test_suite():
+    t1 = makeSuite(PrincipalClipboardTest)
+    return TestSuite((t1,))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')
+