Skip to content

Commit

Permalink
Merge pull request #383 from plone/maurits-test-long-event-master
Browse files Browse the repository at this point in the history
Fix test_long_event when run around midnight of first day of month
  • Loading branch information
mauritsvanrees authored Oct 5, 2023
2 parents e040c0e + 9ff0aa9 commit 71757d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions news/334.tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix test_long_event when run around midnight of the first day of the month.
Fixes `issue 334 <https://github.com/plone/plone.app.event/issues/334>`_.
[maurits]
22 changes: 21 additions & 1 deletion plone/app/event/tests/test_portlet_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,36 @@ def test_portlet_config(self):
self.assertTrue("?mode=day&amp;date=" in rd)

def test_long_event(self):
"""Test a long event.
An event happening on three days, should have an indication on all
three days. That is the main thing we test here.
But the test may fail on the first day of the month.
See https://github.com/plone/plone.app.event/issues/334
When generating the portlet on the first day of the month, it seems
depending on time zones we might get the previous month. This would
mean our event is not (fully) visible. So we force showing the
calendar of the month that we want. This test is not about whether
the correct month is shown at one minute past midnight.
Previously we created an event on the first day. But depending on
the day of the week that the new month starts, this may also influence
what is visible: we may see Friday 1st and Saturday 2nd, but not
Sunday 3rd. So now we pick a day in the middle of the month.
"""
tz = pytz.timezone(TZNAME)
actual = tz.localize(datetime.now())
start = tz.localize(datetime(actual.year, actual.month, 1))
start = tz.localize(datetime(actual.year, actual.month, 15))
end = start + timedelta(days=2)

e1 = createContentInContainer(
self.portal, PTYPE, title="e1", start=start, end=end
)
self.portal.portal_workflow.doActionFor(e1, "publish")

self.request["year"] = actual.year
self.request["month"] = actual.month
r = self.renderer(assignment=portlet_calendar.Assignment(state=("published",)))
r.update()
rd = r.render()
Expand Down

0 comments on commit 71757d6

Please sign in to comment.