[Zope3-checkins] CVS: Zope3/src/zope/app/copypastemove/tests - __init__.py:1.1 test_clipboard.py:1.1 test_rename.py:1.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Mar 13 18:34:44 EST 2004


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

Added Files:
	__init__.py test_clipboard.py test_rename.py 
Log Message:


Move clipboard tests to zope.app.copypaste.move. To do this, I had to
resturcture the tests module to a package.


=== Added File Zope3/src/zope/app/copypastemove/tests/__init__.py ===
# Import this.


=== Added File Zope3/src/zope/app/copypastemove/tests/test_clipboard.py ===
##############################################################################
#
# 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.
#
##############################################################################
"""Clipboard tests

$Id: test_clipboard.py,v 1.1 2004/03/13 23:34:43 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite

from zope.app import zapi
from zope.app.tests import ztapi
from zope.app.principalannotation import PrincipalAnnotationService
from zope.app.principalannotation.interfaces import IPrincipalAnnotationService
from zope.app.annotation.interfaces import IAnnotations

from zope.app.copypastemove.interfaces import IPrincipalClipboard
from zope.app.copypastemove import PrincipalClipboard
from zope.app.pluggableauth.tests.authsetup import AuthSetup


class PrincipalClipboardTest(AuthSetup, TestCase):

    def setUp(self):
        AuthSetup.setUp(self)
        self.buildFolders()

        ztapi.provideAdapter(IAnnotations, IPrincipalClipboard,
                             PrincipalClipboard)
        root_sm = zapi.getServiceManager(None)
        svc = PrincipalAnnotationService()
        root_sm.defineService("PrincipalAnnotation", \
            IPrincipalAnnotationService)
        root_sm.provideService("PrincipalAnnotation", svc)
        sm = zapi.getServiceManager(self.rootFolder)
        sm.PrincipalAnnotation = svc
        self.svc = zapi.getService(self.rootFolder, "PrincipalAnnotation")

    def testAddItems(self):
        user = self._auth['one']['srichter']

        annotationsvc = zapi.getService(self, 'PrincipalAnnotation')
        annotations = annotationsvc.getAnnotations(user)
        clipboard = IPrincipalClipboard(annotations)
        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):
        user = self._auth['one']['srichter']

        annotationsvc = zapi.getService(self, 'PrincipalAnnotation')
        annotations = annotationsvc.getAnnotations(user)
        clipboard = IPrincipalClipboard(annotations)

        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):
        user = self._auth['one']['srichter']

        annotationsvc = zapi.getService(self, 'PrincipalAnnotation')
        annotations = annotationsvc.getAnnotations(user)
        clipboard = IPrincipalClipboard(annotations)
        clipboard.clearContents()
        self.failUnless(clipboard.getContents() == ())

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

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



=== Added File Zope3/src/zope/app/copypastemove/tests/test_rename.py ===
##############################################################################
#
# 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_rename.py,v 1.1 2004/03/13 23:34:43 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite

from zope.testing.doctestunit import DocTestSuite
from zope.app.tests.placelesssetup import setUp, tearDown
from zope.app.tests import ztapi

from zope.exceptions import NotFoundError, DuplicationError
from zope.app.traversing import traverse
from zope.app.site.tests.placefulsetup import PlacefulSetup
from zope.app.container.interfaces import IContainer
from zope.app.copypastemove.interfaces import IObjectMover
from zope.app.copypastemove import ObjectMover
from zope.app.copypastemove import rename

class File:
    pass

class RenameTest(PlacefulSetup, TestCase):

    def setUp(self):
        PlacefulSetup.setUp(self)
        PlacefulSetup.buildFolders(self)
        ztapi.provideAdapter(None, IObjectMover, ObjectMover)

    def test_simplerename(self):
        root = self.rootFolder
        folder1 = traverse(root, 'folder1')
        self.failIf('file1' in folder1)
        folder1['file1'] = File()
        rename(folder1, 'file1', 'my_file1')
        self.failIf('file1' in folder1)
        self.failUnless('my_file1' in folder1)

    def test_renamenonexisting(self):
        root = self.rootFolder
        folder1 = traverse(root, 'folder1')
        self.failIf('a_test_file' in folder1)
        self.assertRaises(NotFoundError, rename, folder1, 'file1', 'my_file1')

    def test_renamesamename(self):
        root = self.rootFolder
        folder1 = traverse(root, 'folder1')
        self.failIf('file1' in folder1)
        self.failIf('file2' in folder1)
        folder1['file1'] = File()
        folder1['file2'] = File()
        self.assertRaises(DuplicationError, rename, folder1, 'file1', 'file2')

def test_suite():
    suite = makeSuite(RenameTest)
    suite.addTest(
        DocTestSuite('zope.app.copypastemove',
                     setUp=setUp, tearDown=tearDown),
        )
    return suite

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




More information about the Zope3-Checkins mailing list