From 5408d3fa8295131f9ddff3e3bc6cd48c44e56244 Mon Sep 17 00:00:00 2001 From: Mikel Larreategi Date: Thu, 10 Oct 2024 17:12:12 +0200 Subject: [PATCH] conditional tests --- src/plone/restapi/serializer/summary.py | 5 +--- .../restapi/tests/test_serializer_summary.py | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/plone/restapi/serializer/summary.py b/src/plone/restapi/serializer/summary.py index 8b8c36dc9..a18ed98a8 100644 --- a/src/plone/restapi/serializer/summary.py +++ b/src/plone/restapi/serializer/summary.py @@ -83,10 +83,7 @@ def __init__(self, context, request): self.blocklisted_attributes = metadata["blocklisted_attributes"] def __call__(self): - try: - obj = IContentListingObject(self.context) - except TypeError: - return {} + obj = IContentListingObject(self.context) summary = {} for field in self.metadata_fields(): diff --git a/src/plone/restapi/tests/test_serializer_summary.py b/src/plone/restapi/tests/test_serializer_summary.py index 2736b4040..05d0a864b 100644 --- a/src/plone/restapi/tests/test_serializer_summary.py +++ b/src/plone/restapi/tests/test_serializer_summary.py @@ -18,6 +18,13 @@ import Missing import unittest +import pkg_resources + + +try: + from plone.app.event.adapters import OccurrenceContentListingObject +except ImportError: + OccurrenceContentListingObject = None class TestSummarySerializers(unittest.TestCase): @@ -245,7 +252,24 @@ def setUp(self): def tearDown(self): popGlobalRegistry(getSite()) - def test_dx_event_with_recurrence(self): + @unittest.skipIf( + OccurrenceContentListingObject is not None, + "this test needs a plone.app.event version that does not include a IContentListingObject adapter", + ) + def test_dx_event_with_recurrence_old_version(self): + tomorrow = datetime.now() + timedelta(days=1) + tomorrow_str = tomorrow.strftime("%Y-%m-%d") + ot = OccurrenceTraverser(self.event, self.request) + ocurrence = ot.publishTraverse(self.request, tomorrow_str) + + with self.assertRaises(TypeError): + getMultiAdapter((ocurrence, self.request), ISerializeToJsonSummary)() + + @unittest.skipIf( + OccurrenceContentListingObject is None, + "this test needs a plone.app.event version that includes a IContentListingObject adapter", + ) + def test_dx_event_with_recurrence_new_version(self): tomorrow = datetime.now() + timedelta(days=1) tomorrow_str = tomorrow.strftime("%Y-%m-%d") ot = OccurrenceTraverser(self.event, self.request)