1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-08-28 19:40:54 +00:00

- Fix unit tests for hook email trigger conditional based on end date

This commit is contained in:
Nate Harris 2025-08-21 00:21:11 -06:00
parent 9b6ba72fa0
commit 998b2e2121
2 changed files with 29 additions and 28 deletions

View file

@ -981,10 +981,13 @@ class Hook(BaseHook):
return
email_event_end_time = email_event_event.datetime_end # type: ignore
# Skip notification if the event end time is more than 1 minute in the past.
if email_event_end_time and email_event_end_time.time and email_event_end_time.time < (
datetime.now() - timedelta(minutes=1)):
logger.warning("Event end time is in the past, skipping notification for event: %s",
email_event_event.uid)
if email_event_end_time and email_event_end_time.time:
event_end = email_event_end_time.time # type: ignore
now = datetime.now(
event_end.tzinfo) if event_end.tzinfo else datetime.now() # Handle timezone-aware datetime
if event_end < (now - timedelta(minutes=1)):
logger.warning("Event end time is in the past, skipping notification for event: %s",
email_event_event.uid)
return
if not previous_item_str:

View file

@ -93,16 +93,12 @@ permissions: RrWw""")
assert "VEVENT" in answer
assert "Event" in answer
assert "UID:event" in answer
found = 0
for line in caplog.messages:
if line.find("notification_item: {'type': 'upsert'") != -1:
found = found | 1
if line.find("to_addresses=['janedoe@example.com']") != -1:
found = found | 2
if line.find("to_addresses=['johndoe@example.com']") != -1:
found = found | 4
if (found != 7):
raise ValueError("Logging misses expected log lines, found=%d", found)
logs = caplog.messages
# Should have a log saying the notification item was received
assert len([log for log in logs if "received notification_item: {'type': 'upsert'," in log]) == 1
# Should NOT have a log saying that no email is sent (email won't actually be sent due to dryrun)
assert len([log for log in logs if "skipping notification for event: event1" in log]) == 0
def test_add_event_with_past_end_date(self, caplog) -> None:
caplog.set_level(logging.WARNING)
@ -119,8 +115,11 @@ permissions: RrWw""")
assert "Event" in answer
assert "UID:event" in answer
# Should not trigger an email
assert len(caplog.messages) == 0
logs = caplog.messages
# Should have a log saying the notification item was received
assert len([log for log in logs if "received notification_item: {'type': 'upsert'," in log]) == 1
# Should have a log saying that no email is sent due to past end date
assert len([log for log in logs if "Event end time is in the past, skipping notification for event: event1" in log]) == 1
def test_delete_event_with_future_end_date(self, caplog) -> None:
caplog.set_level(logging.WARNING)
@ -134,16 +133,12 @@ permissions: RrWw""")
assert responses[path] == 200
_, answer = self.get("/calendar.ics/")
assert "VEVENT" not in answer
found = 0
for line in caplog.messages:
if line.find("notification_item: {'type': 'delete'") != -1:
found = found | 1
if line.find("to_addresses=['janedoe@example.com']") != -1:
found = found | 2
if line.find("to_addresses=['johndoe@example.com']") != -1:
found = found | 4
if (found != 7):
raise ValueError("Logging misses expected log lines, found=%d", found)
logs = caplog.messages
# Should have a log saying the notification item was received
assert len([log for log in logs if "received notification_item: {'type': 'delete'," in log]) == 1
# Should NOT have a log saying that no email is sent (email won't actually be sent due to dryrun)
assert len([log for log in logs if "skipping notification for event: event1" in log]) == 0
def test_delete_event_with_past_end_date(self, caplog) -> None:
caplog.set_level(logging.WARNING)
@ -158,5 +153,8 @@ permissions: RrWw""")
_, answer = self.get("/calendar.ics/")
assert "VEVENT" not in answer
# Should not trigger an email
assert len(caplog.messages) == 0
logs = caplog.messages
# Should have a log saying the notification item was received
assert len([log for log in logs if "received notification_item: {'type': 'delete'," in log]) == 1
# Should have a log saying that no email is sent due to past end date
assert len([log for log in logs if "Event end time is in the past, skipping notification for event: event1" in log]) == 1