Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix in @scadenziario endpoint: return future events if afterToday cri… #242

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ Changelog
6.1.14 (unreleased)
-------------------

- Fix in @scadenziario endpoint: return future events if afterToday criteria is set.
[cekk]
- Set base view to News Item, to do not break on Classic Plone.
[cekk]
- Change description for field sede in UnitaOrganizzativa CT.
- Fixed typo in update_note field description.
[eikichi18]



6.1.13 (2024-02-08)
-------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ def reply(self):
if "start" in query_for_catalog:
start = query_for_catalog["start"]["query"]
if "end" in query_for_catalog:
end = query_for_catalog["end"]["query"]
if query_for_catalog["end"].get("range", "") != "min":
# per esempio, è impostato il filtro "con fine evento da domani".
# se impostiamo un'end (la data di domani), poi nella generazione delle ricorrenze,
# vengono scartati tutti gli eventi che hanno una data di inizio nel futuro
# (https://github.com/plone/plone.event/blob/master/plone/event/recurrence.py#L141)
# perché la data della ricorrenza è maggiore di "until", che è quello che qui inviamo come end.
end = query_for_catalog["end"]["query"]
expanded_events = self.expand_events(events, 3, start, end)

all_results = not_events + expanded_events
Expand Down
89 changes: 89 additions & 0 deletions src/design/plone/contenttypes/tests/test_service_scadenziario.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from datetime import timedelta
from design.plone.contenttypes.testing import (
DESIGN_PLONE_CONTENTTYPES_API_FUNCTIONAL_TESTING,
)
from plone import api
from plone.app.testing import setRoles
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import SITE_OWNER_PASSWORD
from plone.app.testing import TEST_USER_ID
from plone.restapi.testing import RelativeSession
from transaction import commit

import unittest


class ScadenziarioTest(unittest.TestCase):
layer = DESIGN_PLONE_CONTENTTYPES_API_FUNCTIONAL_TESTING

def setUp(self):
self.app = self.layer["app"]
self.portal = self.layer["portal"]
self.request = self.layer["request"]
self.portal_url = self.portal.absolute_url()

self.api_session = RelativeSession(self.portal_url)
self.api_session.headers.update({"Accept": "application/json"})
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)

setRoles(self.portal, TEST_USER_ID, ["Manager"])

commit()

def tearDown(self):
self.api_session.close()

def test_return_future_events_if_query_is_end_after_today(self):
now = datetime.now()

# past event
api.content.create(
container=self.portal,
type="Event",
title="Past event",
start=now.replace(hour=8) + timedelta(days=-2),
end=now.replace(hour=18) + timedelta(days=-2),
)

future_event_1 = api.content.create(
container=self.portal,
type="Event",
title="Future event",
start=now.replace(hour=8) + timedelta(days=2),
end=now.replace(hour=18) + timedelta(days=4),
)
future_event_2 = api.content.create(
container=self.portal,
type="Event",
title="Future event that starts in the past",
start=now.replace(hour=8) + timedelta(days=-4),
end=now.replace(hour=18) + timedelta(days=4),
)

commit()

response = self.api_session.post(
f"{self.portal_url}/@scadenziario",
json={
"query": [
{
"i": "end",
"o": "plone.app.querystring.operation.date.afterToday",
"v": "",
}
]
},
).json()
self.assertEqual(len(response["items"]), 2)

# results are in asc order
self.assertEqual(
response["items"][0],
future_event_2.start.strftime("%Y/%m/%d"),
)
self.assertEqual(
response["items"][1],
future_event_1.start.strftime("%Y/%m/%d"),
)
Loading