/usr/lib/python2.7/dist-packages/zope/copypastemove/tests/test_objectmover.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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | ##############################################################################
#
# 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 Mover 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 ObjectMover
from zope.copypastemove.interfaces import IObjectMover
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_move_events():
"""
We need a root folder::
>>> from zope.container.sample import SampleContainer
>>> root = SampleContainer()
Prepare the setup::
>>> from zope import component
>>> component.provideAdapter(ObjectMover, (None,), IObjectMover)
Prepare some objects::
>>> folder = SampleContainer()
>>> root[u'foo'] = File()
>>> root[u'folder'] = folder
>>> list(folder.keys())
[]
>>> foo = traverse(root, 'foo') # wrap in ContainedProxy
Now move it::
>>> clearEvents()
>>> mover = IObjectMover(foo)
>>> mover.moveableTo(folder)
True
>>> mover.moveTo(folder, u'bar')
u'bar'
Check that the move has been done::
>>> list(root.keys())
[u'folder']
>>> list(folder.keys())
[u'bar']
Check what events have been sent::
>>> events = getEvents()
>>> [event.__class__.__name__ for event in events]
['ObjectMovedEvent', 'ContainerModifiedEvent', 'ContainerModifiedEvent']
Verify that the ObjectMovedEvent includes the correct data::
>>> events[0].oldName, events[0].newName
(u'foo', u'bar')
>>> events[0].oldParent is root
True
>>> events[0].newParent is folder
True
Let's look the other events:
>>> events[1].object is folder
True
>>> events[2].object is root
True
"""
class ObjectMoverTest(testing.ContainerPlacefulSetup, unittest.TestCase):
def setUp(self):
testing.ContainerPlacefulSetup.setUp(self)
self.buildFolders()
zope.component.provideAdapter(ObjectMover, (None,), )
def test_movetosame(self):
# Should be a noop, because "moving" to same location
root = self.rootFolder
container = traverse(root, 'folder1')
container['file1'] = File()
file = traverse(root, 'folder1/file1')
mover = IObjectMover(file)
mover.moveTo(container, 'file1')
self.failUnless('file1' in container)
self.assertEquals(len(container), 2)
def test_movetosamewithnewname(self):
root = self.rootFolder
container = traverse(root, 'folder1')
container['file1'] = File()
file = traverse(root, 'folder1/file1')
mover = IObjectMover(file)
mover.moveTo(container, 'file2')
self.failIf('file1' in container)
self.failUnless('file2' in container)
def test_movetoother(self):
root = self.rootFolder
container = traverse(root, 'folder1')
container['file1'] = File()
target = traverse(root, 'folder2')
file = traverse(root, 'folder1/file1')
mover = IObjectMover(file)
mover.moveTo(target, 'file1')
self.failIf('file1' in container)
self.failUnless('file1' in target)
def test_movetootherwithnewname(self):
root = self.rootFolder
container = traverse(root, 'folder1')
container['file1'] = File()
target = traverse(root, 'folder2')
file = traverse(root, 'folder1/file1')
mover = IObjectMover(file)
mover.moveTo(target, 'file2')
self.failIf('file1' in container)
self.failUnless('file2' in target)
def test_movetootherwithnamecollision(self):
root = self.rootFolder
container = traverse(root, 'folder1')
container['file1'] = File()
target = traverse(root, 'folder2')
target['file1'] = File()
file = traverse(root, 'folder1/file1')
mover = IObjectMover(file)
mover.moveTo(target, 'file1')
self.failIf('file1' in container)
self.failUnless('file1' in target)
self.failUnless('file1-2' in target)
def test_moveable(self):
root = self.rootFolder
container = traverse(root, 'folder1')
container['file1'] = File()
file = traverse(root, 'folder1/file1')
mover = IObjectMover(file)
self.failUnless(mover.moveable())
def test_moveableTo(self):
# A file should be moveable 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')
mover = IObjectMover(file)
self.failUnless(mover.moveableTo(container, 'file1'))
def test_movefoldertosibling(self):
root = self.rootFolder
target = traverse(root, '/folder2')
source = traverse(root, '/folder1/folder1_1')
mover = IObjectMover(source)
mover.moveTo(target)
self.failUnless('folder1_1' in target)
def test_movefoldertosame(self):
# Should be a noop, because "moving" to same location
root = self.rootFolder
target = traverse(root, '/folder1')
source = traverse(root, '/folder1/folder1_1')
mover = IObjectMover(source)
mover.moveTo(target)
self.failUnless('folder1_1' in target)
self.assertEquals(len(target), 1)
def test_movefoldertosame2(self):
# Should be a noop, because "moving" to same location
root = self.rootFolder
target = traverse(root, '/folder1/folder1_1')
source = traverse(root, '/folder1/folder1_1/folder1_1_1')
mover = IObjectMover(source)
mover.moveTo(target)
self.failUnless('folder1_1_1' in target)
self.assertEquals(len(target), 1)
def test_movefolderfromroot(self):
root = self.rootFolder
target = traverse(root, '/folder2')
source = traverse(root, '/folder1')
mover = IObjectMover(source)
mover.moveTo(target)
self.failUnless('folder1' in target)
def test_movefolderfromroot2(self):
root = self.rootFolder
target = traverse(root, '/folder2/folder2_1/folder2_1_1')
source = traverse(root, '/folder1')
mover = IObjectMover(source)
mover.moveTo(target)
self.failUnless('folder1' in target)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ObjectMoverTest),
doctest.DocTestSuite(
setUp=testing.ContainerPlacefulSetup().setUp,
tearDown=testing.ContainerPlacefulSetup().tearDown,
checker=checker),
))
|