64
63
>>> zope.event.subscribers[:] = old_subscribers
70
def doctest_copy_breaks_relationships():
71
"""When you copy an object, all of its relationships should be removed
73
(An alternative solution would be to clone the relationships, but I'm
74
wary of that path. What happens if you copy and paste objects between
75
different application instances?)
77
>>> from schooltool.relationship.tests import setUp, tearDown
81
>>> old_subscribers = zope.event.subscribers[:]
82
>>> from schooltool.relationship.objectevents import unrelateOnCopy
83
>>> zope.event.subscribers.append(unrelateOnCopy)
85
Suppose we have two related objects. We must have objects that are
86
IContained, otherwise ObjectCopier will happily duplicate all related
87
objects as well as relationship links.
89
>>> from schooltool.relationship.tests import SomeContained
90
>>> apple = SomeContained('apple')
91
>>> orange = SomeContained('orange')
93
>>> from schooltool.relationship import getRelatedObjects, relate
94
>>> relate('example:Relationship',
95
... (apple, URIStub('example:One')),
96
... (orange, URIStub('example:Two')))
97
>>> getRelatedObjects(apple, URIStub('example:Two'))
100
We put those objects to a Zope 3 container.
102
>>> from zope.container.btree import BTreeContainer
103
>>> container = BTreeContainer()
104
>>> container['apple'] = apple
105
>>> container['orange'] = orange
107
We copy one of the objects to another container.
109
>>> from zope.copypastemove import ObjectCopier
110
>>> another_container = BTreeContainer()
111
>>> copier = ObjectCopier(container['orange'])
112
>>> new_name = copier.copyTo(another_container)
113
>>> copy_of_orange = another_container[new_name]
115
When we copy an object, all of its relationships should disappear
117
>>> from schooltool.relationship.interfaces import IRelationshipLinks
118
>>> list(IRelationshipLinks(copy_of_orange))
121
The old relationships should still work
123
>>> getRelatedObjects(apple, URIStub('example:Two'))
125
>>> getRelatedObjects(orange, URIStub('example:One'))
128
>>> zope.event.subscribers[:] = old_subscribers
134
def doctest_copy_does_not_break_inside_relationships():
135
"""When you copy an object, all of its relationships should be removed
137
This is a regression test for the following bug: If x is related to x.y
138
where x.y is a subobject of x, when you copy x to x', all links from x'
139
will be removed, but the copied link on x'.y' will remain.
141
>>> from schooltool.relationship.tests import setUp, tearDown
144
>>> import zope.event
145
>>> old_subscribers = zope.event.subscribers[:]
146
>>> from schooltool.relationship.objectevents import unrelateOnCopy
147
>>> zope.event.subscribers.append(unrelateOnCopy)
149
Suppose we have two related objects. We must have objects that are
150
IContained, otherwise ObjectCopier will happily duplicate all related
151
objects as well as relationship links.
153
>>> from schooltool.relationship.tests import SomeContained
154
>>> apple = SomeContained('apple')
155
>>> orange = SomeContained('orange')
157
>>> from schooltool.relationship import getRelatedObjects, relate
158
>>> relate(URIStub('example:Relationship'),
159
... (apple, URIStub('example:One')),
160
... (orange, URIStub('example:Two')))
161
>>> getRelatedObjects(apple, URIStub('example:Two'))
164
We put one of the objects to a Zope 3 container.
166
>>> from zope.container.btree import BTreeContainer
167
>>> container = BTreeContainer()
168
>>> container['orange'] = orange
170
We make the other object a subobject of the first object
172
>>> apple.__parent__ = orange
173
>>> apple.__name__ = 'apple'
174
>>> orange.apple = apple
176
We copy the first object to another container.
178
>>> from zope.copypastemove import ObjectCopier
179
>>> another_container = BTreeContainer()
180
>>> copier = ObjectCopier(container['orange'])
181
>>> new_name = copier.copyTo(another_container)
182
>>> copy_of_orange = another_container[new_name]
183
>>> copy_of_apple = copy_of_orange.apple
185
>>> r1 = URIStub('example:One')
186
>>> r2 = URIStub('example:Two')
188
When we copy an object, its internal relationships should remain
190
>>> getRelatedObjects(copy_of_orange, r1)
192
>>> getRelatedObjects(copy_of_apple, r2)
195
These two objects are, in fact, copies
197
>>> getRelatedObjects(copy_of_orange, r1)[0] is copy_of_apple
199
>>> getRelatedObjects(copy_of_apple, r2)[0] is copy_of_orange
202
The old relationships should still work
204
>>> getRelatedObjects(apple, r2)
206
>>> getRelatedObjects(orange, r1)
209
>>> zope.event.subscribers[:] = old_subscribers
67
# XXX: disabled copy tests since we don't copy related objects anywhere
68
#def doctest_copy_breaks_relationships():
69
# """When you copy an object, all of its relationships should be removed
71
# (An alternative solution would be to clone the relationships, but I'm
72
# wary of that path. What happens if you copy and paste objects between
73
# different application instances?)
75
# >>> from schooltool.relationship.tests import setUp, tearDown
78
# >>> import zope.event
79
# >>> old_subscribers = zope.event.subscribers[:]
80
# >>> from schooltool.relationship.objectevents import unrelateOnCopy
81
# >>> zope.event.subscribers.append(unrelateOnCopy)
83
# Suppose we have two related objects. We must have objects that are
84
# IContained, otherwise ObjectCopier will happily duplicate all related
85
# objects as well as relationship links.
87
# >>> from schooltool.relationship.tests import SomeContained
88
# >>> apple = SomeContained('apple')
89
# >>> orange = SomeContained('orange')
91
# >>> from schooltool.relationship import getRelatedObjects, relate
92
# >>> relate('example:Relationship',
93
# ... (apple, URIStub('example:One')),
94
# ... (orange, URIStub('example:Two')))
95
# >>> getRelatedObjects(apple, URIStub('example:Two'))
98
# We put those objects to a Zope 3 container.
100
# >>> from zope.container.btree import BTreeContainer
101
# >>> container = BTreeContainer()
102
# >>> container['apple'] = apple
103
# >>> container['orange'] = orange
105
# We copy one of the objects to another container.
107
# >>> from zope.copypastemove import ObjectCopier
108
# >>> another_container = BTreeContainer()
109
# >>> copier = ObjectCopier(container['orange'])
110
# >>> new_name = copier.copyTo(another_container)
111
# >>> copy_of_orange = another_container[new_name]
113
# When we copy an object, all of its relationships should disappear
115
# >>> from schooltool.relationship.interfaces import IRelationshipLinks
116
# >>> list(IRelationshipLinks(copy_of_orange))
119
# The old relationships should still work
121
# >>> getRelatedObjects(apple, URIStub('example:Two'))
123
# >>> getRelatedObjects(orange, URIStub('example:One'))
126
# >>> zope.event.subscribers[:] = old_subscribers
132
#def doctest_copy_does_not_break_inside_relationships():
133
# """When you copy an object, all of its relationships should be removed
135
# This is a regression test for the following bug: If x is related to x.y
136
# where x.y is a subobject of x, when you copy x to x', all links from x'
137
# will be removed, but the copied link on x'.y' will remain.
139
# >>> from schooltool.relationship.tests import setUp, tearDown
142
# >>> import zope.event
143
# >>> old_subscribers = zope.event.subscribers[:]
144
# >>> from schooltool.relationship.objectevents import unrelateOnCopy
145
# >>> zope.event.subscribers.append(unrelateOnCopy)
147
# Suppose we have two related objects. We must have objects that are
148
# IContained, otherwise ObjectCopier will happily duplicate all related
149
# objects as well as relationship links.
151
# >>> from schooltool.relationship.tests import SomeContained
152
# >>> apple = SomeContained('apple')
153
# >>> orange = SomeContained('orange')
155
# >>> from schooltool.relationship import getRelatedObjects, relate
156
# >>> relate(URIStub('example:Relationship'),
157
# ... (apple, URIStub('example:One')),
158
# ... (orange, URIStub('example:Two')))
159
# >>> getRelatedObjects(apple, URIStub('example:Two'))
162
# We put one of the objects to a Zope 3 container.
164
# >>> from zope.container.btree import BTreeContainer
165
# >>> container = BTreeContainer()
166
# >>> container['orange'] = orange
168
# We make the other object a subobject of the first object
170
# >>> apple.__parent__ = orange
171
# >>> apple.__name__ = 'apple'
172
# >>> orange.apple = apple
174
# We copy the first object to another container.
176
# >>> from zope.copypastemove import ObjectCopier
177
# >>> another_container = BTreeContainer()
178
# >>> copier = ObjectCopier(container['orange'])
179
# >>> new_name = copier.copyTo(another_container)
180
# >>> copy_of_orange = another_container[new_name]
181
# >>> copy_of_apple = copy_of_orange.apple
183
# >>> r1 = URIStub('example:One')
184
# >>> r2 = URIStub('example:Two')
186
# When we copy an object, its internal relationships should remain
188
# >>> getRelatedObjects(copy_of_orange, r1)
190
# >>> getRelatedObjects(copy_of_apple, r2)
193
# These two objects are, in fact, copies
195
# >>> getRelatedObjects(copy_of_orange, r1)[0] is copy_of_apple
197
# >>> getRelatedObjects(copy_of_apple, r2)[0] is copy_of_orange
200
# The old relationships should still work
202
# >>> getRelatedObjects(apple, r2)
204
# >>> getRelatedObjects(orange, r1)
207
# >>> zope.event.subscribers[:] = old_subscribers
215
213
def test_suite():
216
214
return unittest.TestSuite([
217
doctest.DocTestSuite(),
215
doctest.DocTestSuite(setUp=setUp, tearDown=tearDown),
220
218
if __name__ == '__main__':