|
27 | 27 | from zope.component import provideAdapter
|
28 | 28 | from zope.component import queryUtility
|
29 | 29 | from zope.interface import Interface
|
| 30 | +from z3c.relationfield import RelationValue |
| 31 | +from z3c.relationfield.event import _setRelation |
| 32 | +from zope.component import getUtility |
| 33 | +from zope.intid.interfaces import IIntIds |
30 | 34 | from zope.publisher.interfaces.browser import IBrowserRequest
|
31 | 35 | from importlib import import_module
|
32 | 36 |
|
@@ -191,6 +195,30 @@ def test_serializer_includes_expansion(self):
|
191 | 195 | "foo",
|
192 | 196 | )
|
193 | 197 |
|
| 198 | + def test_serializer_excludes_deleted_relations(self): |
| 199 | + |
| 200 | + intids = getUtility(IIntIds) |
| 201 | + self.portal.invokeFactory( |
| 202 | + "DXTestDocument", |
| 203 | + id="doc2", |
| 204 | + ) |
| 205 | + rel1 = RelationValue(intids.getId(self.portal.doc1)) |
| 206 | + rel2 = RelationValue(intids.getId(self.portal.doc2)) |
| 207 | + self.portal.doc1.test_relationlist_field = [ |
| 208 | + rel1, |
| 209 | + rel2, |
| 210 | + ] |
| 211 | + _setRelation(self.portal.doc1, "test_relationlist_field", rel1) |
| 212 | + _setRelation(self.portal.doc1, "test_relationlist_field", rel2) |
| 213 | + # delete doc2 to make sure we have a None value in the relation list |
| 214 | + self.portal.manage_delObjects(["doc2"]) |
| 215 | + |
| 216 | + obj = self.serialize() |
| 217 | + self.assertEqual(1, len(obj["test_relationlist_field"])) |
| 218 | + self.assertEqual( |
| 219 | + "http://nohost/plone/doc1", obj["test_relationlist_field"][0]["@id"] |
| 220 | + ) |
| 221 | + |
194 | 222 | def test_get_is_folderish(self):
|
195 | 223 | obj = self.serialize()
|
196 | 224 | self.assertIn("is_folderish", obj)
|
|
0 commit comments