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

Sidnei da Silva sidnei@x3ng.com.br
Wed, 5 Feb 2003 05:09:29 -0500


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

Added Files:
      Tag: paris-copypasterename-branch
	test_clipboard.py 
Log Message:
Fixing ObjectMover tests. Adding ObjectCopier tests. Adding AnnotatableUserClipboard with tests. That was a productive night :)

=== Added File Zope3/src/zope/app/tests/test_clipboard.py ===
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: test_clipboard.py,v 1.1.2.1 2003/02/05 10:09:24 sidnei Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.interfaces.copy import IAnnotatableUserClipboard
from zope.app.copy import AnnotatableUserClipboard
from zope.app.interfaces.services.auth import IUser
from zope.component import getAdapter
from zope.component.adapter import provideAdapter

class AnnotatableUserClipboardTest(AuthSetup, TestCase):
    
    def setUp(self):
        AuthSetup.setUp(self)
        provideAdapter(IUser, IAnnotatableUserClipboard, AnnotatableUserClipboard)

    def testAddItems(self):
        auth = self._auth
        user = auth.getPrincipalByLogin('srichter')
        clipboard = getAdapter(user, IAnnotatableUserClipboard)
        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')
        clipboard = getAdapter(user, IAnnotatableUserClipboard)
        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')
        clipboard = getAdapter(user, IAnnotatableUserClipboard)
        clipboard.clearContents()
        self.failUnless(clipboard.getContents() == ())

def test_suite():
    t1 = makeSuite(AnnotatableUserClipboardTest)
    return TestSuite((t1,))

if __name__=='__main__':
    main(defaultTest='test_suite')