From 4805c930298a889f70fbe40bfde46f8483322436 Mon Sep 17 00:00:00 2001 From: Faakhir30 Date: Sat, 28 Sep 2024 23:31:17 +0500 Subject: [PATCH] Add test to check deleted relations --- src/plone/restapi/serializer/relationfield.py | 3 --- .../tests/test_dxcontent_serializer.py | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/plone/restapi/serializer/relationfield.py b/src/plone/restapi/serializer/relationfield.py index 82d9879a6..1eb2c69e8 100644 --- a/src/plone/restapi/serializer/relationfield.py +++ b/src/plone/restapi/serializer/relationfield.py @@ -7,7 +7,6 @@ from z3c.relationfield.interfaces import IRelationChoice from z3c.relationfield.interfaces import IRelationList from z3c.relationfield.interfaces import IRelationValue -from z3c.relationfield import RelationValue from zope.component import adapter from zope.component import getMultiAdapter from zope.globalrequest import getRequest @@ -48,6 +47,4 @@ def get_value(self, default=[]): ) if not value: return [] - if isinstance(value, RelationValue): - return [value] return [el for el in value if el.to_object] diff --git a/src/plone/restapi/tests/test_dxcontent_serializer.py b/src/plone/restapi/tests/test_dxcontent_serializer.py index 6fd514956..200ee127c 100644 --- a/src/plone/restapi/tests/test_dxcontent_serializer.py +++ b/src/plone/restapi/tests/test_dxcontent_serializer.py @@ -27,6 +27,9 @@ from zope.component import provideAdapter from zope.component import queryUtility from zope.interface import Interface +from z3c.relationfield import RelationValue +from zope.component import getUtility +from zope.intid.interfaces import IIntIds from zope.publisher.interfaces.browser import IBrowserRequest from importlib import import_module @@ -191,6 +194,26 @@ def test_serializer_includes_expansion(self): "foo", ) + def test_serializer_excludes_deleted_relations(self): + + intids = getUtility(IIntIds) + self.portal.invokeFactory( + "DXTestDocument", + id="doc2", + ) + self.portal.doc1.test_relationlist_field = [ + RelationValue(intids.getId(self.portal.doc1)), + RelationValue(intids.getId(self.portal.doc2)), + ] + # delete doc2 to make sure we have a None value in the relation list + self.portal.manage_delObjects(["doc2"]) + + obj = self.serialize() + self.assertEqual(1, len(obj["test_relationlist_field"])) + self.assertEqual( + "http://nohost/plone/doc1", obj["test_relationlist_field"][0]["@id"] + ) + def test_get_is_folderish(self): obj = self.serialize() self.assertIn("is_folderish", obj)