Skip to content

Commit

Permalink
Add test to check deleted relations
Browse files Browse the repository at this point in the history
  • Loading branch information
Faakhir30 committed Sep 28, 2024
1 parent bde5355 commit 4805c93
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/plone/restapi/serializer/relationfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
23 changes: 23 additions & 0 deletions src/plone/restapi/tests/test_dxcontent_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4805c93

Please sign in to comment.