/usr/lib/python2.7/dist-packages/zope/copypastemove/tests/test_objectcopier.py is in python-zope.copypastemove 4.0.0a1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Object Copier Tests
"""
import doctest
import re
import unittest
import zope.component
from zope.traversing.api import traverse
from zope.component.eventtesting import clearEvents
from zope.component.eventtesting import getEvents
from zope.copypastemove import ObjectCopier
from zope.copypastemove.interfaces import IObjectCopier
from zope.testing import renormalizing
from zope.container import testing
checker = renormalizing.RENormalizing([
# Python 3 unicode removed the "u".
(re.compile("u('.*?')"),
r"\1"),
(re.compile('u(".*?")'),
r"\1"),
])
class File(object):
pass
def test_copy_events():
"""
Prepare an IObjectCopier::
>>> from zope import component
>>> component.provideAdapter(ObjectCopier, (None,), IObjectCopier)
We set things up in a root folder::
>>> from zope.container.sample import SampleContainer
>>> root = SampleContainer()
Prepare some objects::
>>> folder = SampleContainer()
>>> root[u'foo'] = File()
>>> root[u'folder'] = folder
>>> list(folder.keys())
[]
>>> foo = traverse(root, 'foo') # wrap in ContainedProxy
Now make a copy::
>>> clearEvents()
>>> copier = IObjectCopier(foo)
>>> copier.copyTo(folder, u'bar')
u'bar'
Check that the copy has been done::
>>> list(folder.keys())
[u'bar']
Check what events have been sent::
>>> events = getEvents()
>>> [event.__class__.__name__ for event in events]
['ObjectCopiedEvent', 'ObjectAddedEvent', 'ContainerModifiedEvent']
Check that the ObjectCopiedEvent includes the correct data::
>>> events[0].object is folder[u'bar']
True
>>> events[0].original is root[u'foo']
True
"""
class ObjectCopierTest(testing.ContainerPlacefulSetup, unittest.TestCase):
def setUp(self):
testing.ContainerPlacefulSetup.setUp(self)
self.buildFolders()
zope.component.provideAdapter(ObjectCopier, (None,), IObjectCopier)
def test_copytosame(self):
root = self.rootFolder
container = traverse(root, 'folder1')
container['file1'] = File()
file = traverse(root, 'folder1/file1')
copier = IObjectCopier(file)
copier.copyTo(container, 'file1')
self.failUnless('file1' in container)
self.failUnless('file1-2' in container)
def test_copytosamewithnewname(self):
root = self.rootFolder
container = traverse(root, 'folder1')
container['file1'] = File()
file = traverse(root, 'folder1/file1')
copier = IObjectCopier(file)
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['file1'] = File()
target = traverse(root, 'folder2')
file = traverse(root, 'folder1/file1')
copier = IObjectCopier(file)
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['file1'] = File()
target = traverse(root, 'folder2')
file = traverse(root, 'folder1/file1')
copier = IObjectCopier(file)
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['file1'] = File()
target = traverse(root, 'folder2')
target['file1'] = File()
file = traverse(root, 'folder1/file1')
copier = IObjectCopier(file)
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('file1-2' in target)
self.failUnless('file1-3' in target)
def test_copyable(self):
root = self.rootFolder
container = traverse(root, 'folder1')
container['file1'] = File()
file = traverse(root, 'folder1/file1')
copier = IObjectCopier(file)
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['file1'] = File()
file = traverse(root, 'folder1/file1')
copier = IObjectCopier(file)
self.failUnless(copier.copyableTo(container, 'file1'))
def test_copyfoldertosibling(self):
root = self.rootFolder
target = traverse(root, '/folder2')
source = traverse(root, '/folder1/folder1_1')
copier = IObjectCopier(source)
copier.copyTo(target)
self.failUnless('folder1_1' in target)
def test_copyfoldertosame(self):
root = self.rootFolder
target = traverse(root, '/folder1')
source = traverse(root, '/folder1/folder1_1')
copier = IObjectCopier(source)
copier.copyTo(target)
self.failUnless('folder1_1' in target)
def test_copyfoldertosame2(self):
root = self.rootFolder
target = traverse(root, '/folder1/folder1_1')
source = traverse(root, '/folder1/folder1_1/folder1_1_1')
copier = IObjectCopier(source)
copier.copyTo(target)
self.failUnless('folder1_1_1' in target)
def test_copyfolderfromroot(self):
root = self.rootFolder
target = traverse(root, '/folder2')
source = traverse(root, '/folder1')
copier = IObjectCopier(source)
copier.copyTo(target)
self.failUnless('folder1' in target)
def test_copyfolderfromroot2(self):
root = self.rootFolder
target = traverse(root, '/folder2/folder2_1/folder2_1_1')
source = traverse(root, '/folder1')
copier = IObjectCopier(source)
copier.copyTo(target)
self.failUnless('folder1' in target)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ObjectCopierTest),
doctest.DocTestSuite(
setUp=testing.ContainerPlacefulSetup().setUp,
tearDown=testing.ContainerPlacefulSetup().tearDown,
checker=checker),
))
|