~replaceafill/ubuntu/trusty/schooltool/2.8_custom-css

« back to all changes in this revision

Viewing changes to src/schooltool/relationship/tests/test_objectevents.py

  • Committer: Douglas Cerna
  • Date: 2014-10-14 16:05:11 UTC
  • mfrom: (1.1.36)
  • Revision ID: douglascerna@yahoo.com-20141014160511-v2zzlmyuwjsfizai
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import doctest
23
23
 
24
24
from schooltool.relationship.tests import URIStub
 
25
from schooltool.app.tests import setUp, tearDown
25
26
 
26
27
 
27
28
def doctest_delete_breaks_relationships():
28
29
    """When you delete an object, all of its relationships should be removed
29
30
 
30
 
        >>> from schooltool.relationship.tests import setUp, tearDown
31
 
        >>> setUp()
32
 
 
33
31
        >>> import zope.event
34
32
        >>> old_subscribers = zope.event.subscribers[:]
35
33
        >>> from schooltool.relationship.objectevents import unrelateOnDeletion
37
35
 
38
36
    Suppose we have two related objects
39
37
 
40
 
        >>> from schooltool.relationship.tests import SomeObject
41
 
        >>> apple = SomeObject('apple')
42
 
        >>> orange = SomeObject('orange')
 
38
        >>> from schooltool.relationship.tests import SomeContainedPersistent
 
39
        >>> apple = persons['apple'] = SomeContainedPersistent('apple')
 
40
        >>> orange = persons['orange'] = SomeContainedPersistent('orange')
43
41
 
44
42
        >>> from schooltool.relationship import getRelatedObjects, relate
45
 
        >>> relate('example:Relationship',
 
43
        >>> from schooltool.relationship.uri import URIObject as URIStub
 
44
        >>> relate(URIStub('example:Relationship'),
46
45
        ...             (apple, URIStub('example:One')),
47
46
        ...             (orange, URIStub('example:Two')))
48
47
        >>> getRelatedObjects(apple, URIStub('example:Two'))
62
61
        []
63
62
 
64
63
        >>> zope.event.subscribers[:] = old_subscribers
65
 
        >>> tearDown()
66
 
 
67
 
    """
68
 
 
69
 
 
70
 
def doctest_copy_breaks_relationships():
71
 
    """When you copy an object, all of its relationships should be removed
72
 
 
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?)
76
 
 
77
 
        >>> from schooltool.relationship.tests import setUp, tearDown
78
 
        >>> setUp()
79
 
 
80
 
        >>> import zope.event
81
 
        >>> old_subscribers = zope.event.subscribers[:]
82
 
        >>> from schooltool.relationship.objectevents import unrelateOnCopy
83
 
        >>> zope.event.subscribers.append(unrelateOnCopy)
84
 
 
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.
88
 
 
89
 
        >>> from schooltool.relationship.tests import SomeContained
90
 
        >>> apple = SomeContained('apple')
91
 
        >>> orange = SomeContained('orange')
92
 
 
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'))
98
 
        [orange]
99
 
 
100
 
    We put those objects to a Zope 3 container.
101
 
 
102
 
        >>> from zope.container.btree import BTreeContainer
103
 
        >>> container = BTreeContainer()
104
 
        >>> container['apple'] = apple
105
 
        >>> container['orange'] = orange
106
 
 
107
 
    We copy one of the objects to another container.
108
 
 
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]
114
 
 
115
 
    When we copy an object, all of its relationships should disappear
116
 
 
117
 
        >>> from schooltool.relationship.interfaces import IRelationshipLinks
118
 
        >>> list(IRelationshipLinks(copy_of_orange))
119
 
        []
120
 
 
121
 
    The old relationships should still work
122
 
 
123
 
        >>> getRelatedObjects(apple, URIStub('example:Two'))
124
 
        [orange]
125
 
        >>> getRelatedObjects(orange, URIStub('example:One'))
126
 
        [apple]
127
 
 
128
 
        >>> zope.event.subscribers[:] = old_subscribers
129
 
        >>> tearDown()
130
 
 
131
 
    """
132
 
 
133
 
 
134
 
def doctest_copy_does_not_break_inside_relationships():
135
 
    """When you copy an object, all of its relationships should be removed
136
 
 
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.
140
 
 
141
 
        >>> from schooltool.relationship.tests import setUp, tearDown
142
 
        >>> setUp()
143
 
 
144
 
        >>> import zope.event
145
 
        >>> old_subscribers = zope.event.subscribers[:]
146
 
        >>> from schooltool.relationship.objectevents import unrelateOnCopy
147
 
        >>> zope.event.subscribers.append(unrelateOnCopy)
148
 
 
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.
152
 
 
153
 
        >>> from schooltool.relationship.tests import SomeContained
154
 
        >>> apple = SomeContained('apple')
155
 
        >>> orange = SomeContained('orange')
156
 
 
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'))
162
 
        [orange]
163
 
 
164
 
    We put one of the objects to a Zope 3 container.
165
 
 
166
 
        >>> from zope.container.btree import BTreeContainer
167
 
        >>> container = BTreeContainer()
168
 
        >>> container['orange'] = orange
169
 
 
170
 
    We make the other object a subobject of the first object
171
 
 
172
 
        >>> apple.__parent__ = orange
173
 
        >>> apple.__name__ = 'apple'
174
 
        >>> orange.apple = apple
175
 
 
176
 
    We copy the first object to another container.
177
 
 
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
184
 
 
185
 
        >>> r1 = URIStub('example:One')
186
 
        >>> r2 = URIStub('example:Two')
187
 
 
188
 
    When we copy an object, its internal relationships should remain
189
 
 
190
 
        >>> getRelatedObjects(copy_of_orange, r1)
191
 
        [apple]
192
 
        >>> getRelatedObjects(copy_of_apple, r2)
193
 
        [orange]
194
 
 
195
 
    These two objects are, in fact, copies
196
 
 
197
 
        >>> getRelatedObjects(copy_of_orange, r1)[0] is copy_of_apple
198
 
        True
199
 
        >>> getRelatedObjects(copy_of_apple, r2)[0] is copy_of_orange
200
 
        True
201
 
 
202
 
    The old relationships should still work
203
 
 
204
 
        >>> getRelatedObjects(apple, r2)
205
 
        [orange]
206
 
        >>> getRelatedObjects(orange, r1)
207
 
        [apple]
208
 
 
209
 
        >>> zope.event.subscribers[:] = old_subscribers
210
 
        >>> tearDown()
211
 
 
212
 
    """
213
 
 
 
64
 
 
65
    """
 
66
 
 
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
 
70
#
 
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?)
 
74
#
 
75
#        >>> from schooltool.relationship.tests import setUp, tearDown
 
76
#        >>> setUp()
 
77
#
 
78
#        >>> import zope.event
 
79
#        >>> old_subscribers = zope.event.subscribers[:]
 
80
#        >>> from schooltool.relationship.objectevents import unrelateOnCopy
 
81
#        >>> zope.event.subscribers.append(unrelateOnCopy)
 
82
#
 
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.
 
86
#
 
87
#        >>> from schooltool.relationship.tests import SomeContained
 
88
#        >>> apple = SomeContained('apple')
 
89
#        >>> orange = SomeContained('orange')
 
90
#
 
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'))
 
96
#        [orange]
 
97
#
 
98
#    We put those objects to a Zope 3 container.
 
99
#
 
100
#        >>> from zope.container.btree import BTreeContainer
 
101
#        >>> container = BTreeContainer()
 
102
#        >>> container['apple'] = apple
 
103
#        >>> container['orange'] = orange
 
104
#
 
105
#    We copy one of the objects to another container.
 
106
#
 
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]
 
112
#
 
113
#    When we copy an object, all of its relationships should disappear
 
114
#
 
115
#        >>> from schooltool.relationship.interfaces import IRelationshipLinks
 
116
#        >>> list(IRelationshipLinks(copy_of_orange))
 
117
#        []
 
118
#
 
119
#    The old relationships should still work
 
120
#
 
121
#        >>> getRelatedObjects(apple, URIStub('example:Two'))
 
122
#        [orange]
 
123
#        >>> getRelatedObjects(orange, URIStub('example:One'))
 
124
#        [apple]
 
125
#
 
126
#        >>> zope.event.subscribers[:] = old_subscribers
 
127
#        >>> tearDown()
 
128
#
 
129
#    """
 
130
#
 
131
#
 
132
#def doctest_copy_does_not_break_inside_relationships():
 
133
#    """When you copy an object, all of its relationships should be removed
 
134
#
 
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.
 
138
#
 
139
#        >>> from schooltool.relationship.tests import setUp, tearDown
 
140
#        >>> setUp()
 
141
#
 
142
#        >>> import zope.event
 
143
#        >>> old_subscribers = zope.event.subscribers[:]
 
144
#        >>> from schooltool.relationship.objectevents import unrelateOnCopy
 
145
#        >>> zope.event.subscribers.append(unrelateOnCopy)
 
146
#
 
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.
 
150
#
 
151
#        >>> from schooltool.relationship.tests import SomeContained
 
152
#        >>> apple = SomeContained('apple')
 
153
#        >>> orange = SomeContained('orange')
 
154
#
 
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'))
 
160
#        [orange]
 
161
#
 
162
#    We put one of the objects to a Zope 3 container.
 
163
#
 
164
#        >>> from zope.container.btree import BTreeContainer
 
165
#        >>> container = BTreeContainer()
 
166
#        >>> container['orange'] = orange
 
167
#
 
168
#    We make the other object a subobject of the first object
 
169
#
 
170
#        >>> apple.__parent__ = orange
 
171
#        >>> apple.__name__ = 'apple'
 
172
#        >>> orange.apple = apple
 
173
#
 
174
#    We copy the first object to another container.
 
175
#
 
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
 
182
#
 
183
#        >>> r1 = URIStub('example:One')
 
184
#        >>> r2 = URIStub('example:Two')
 
185
#
 
186
#    When we copy an object, its internal relationships should remain
 
187
#
 
188
#        >>> getRelatedObjects(copy_of_orange, r1)
 
189
#        [apple]
 
190
#        >>> getRelatedObjects(copy_of_apple, r2)
 
191
#        [orange]
 
192
#
 
193
#    These two objects are, in fact, copies
 
194
#
 
195
#        >>> getRelatedObjects(copy_of_orange, r1)[0] is copy_of_apple
 
196
#        True
 
197
#        >>> getRelatedObjects(copy_of_apple, r2)[0] is copy_of_orange
 
198
#        True
 
199
#
 
200
#    The old relationships should still work
 
201
#
 
202
#        >>> getRelatedObjects(apple, r2)
 
203
#        [orange]
 
204
#        >>> getRelatedObjects(orange, r1)
 
205
#        [apple]
 
206
#
 
207
#        >>> zope.event.subscribers[:] = old_subscribers
 
208
#        >>> tearDown()
 
209
#
 
210
#    """
 
211
#
214
212
 
215
213
def test_suite():
216
214
    return unittest.TestSuite([
217
 
                doctest.DocTestSuite(),
 
215
                doctest.DocTestSuite(setUp=setUp, tearDown=tearDown),
218
216
           ])
219
217
 
220
218
if __name__ == '__main__':