hook/email: add additional test cases, extend log for that

This commit is contained in:
Peter Bieringer
2026-04-10 08:35:05 +02:00
parent 3158736579
commit 5388740ac2
2 changed files with 57 additions and 3 deletions

View File

@@ -837,7 +837,9 @@ class EmailConfig:
return False return False
if self.dryrun is True: if self.dryrun is True:
logger.warning("Hook 'email': DRY-RUN _send_email / to_addresses=%r", to_addresses) logger.notice("Hook 'email': DRY-RUN _send_email / to_addresses=%r", to_addresses)
logger.notice("Hook 'email': DRY-RUN _send_email / subject=%r", subject)
logger.notice("Hook 'email': DRY-RUN _send_email / body=%r", body)
return True return True
# Add headers # Add headers

View File

@@ -94,7 +94,7 @@ permissions: RrWw""")
f"DTEND;VALUE=DATE:{new_date}", event) f"DTEND;VALUE=DATE:{new_date}", event)
def test_add_event_with_future_end_date(self, caplog) -> None: def test_add_event_with_future_end_date(self, caplog) -> None:
caplog.set_level(logging.WARNING) caplog.set_level(logging.INFO)
"""Add an event.""" """Add an event."""
self.mkcalendar("/calendar.ics/") self.mkcalendar("/calendar.ics/")
event = get_file_content("event1.ics") event = get_file_content("event1.ics")
@@ -112,7 +112,7 @@ permissions: RrWw""")
# Should have a log saying the notification item was received # 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 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) # 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 assert len([log for log in logs if "New event detected, sending notifications to all attendees: event1" in log]) == 1
def test_add_event_with_past_end_date(self, caplog) -> None: def test_add_event_with_past_end_date(self, caplog) -> None:
caplog.set_level(logging.WARNING) caplog.set_level(logging.WARNING)
@@ -210,3 +210,55 @@ permissions: RrWw""")
assert len([log for log in logs if "received notification_item: {'type': 'delete'," in log]) == 1 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 # 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 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_add_event_with_future_mass1_end_date(self, caplog) -> None:
self.configure({"hook": {"type": "email",
"mass_email": "True",
"dryrun": "True"}})
caplog.set_level(logging.INFO)
"""Add an event."""
self.mkcalendar("/calendar.ics/")
event = get_file_content("event1.ics")
event = self._replace_end_date_in_event(event, self._future_date_timestamp())
path = "/calendar.ics/event1.ics"
self.put(path, event)
_, headers, answer = self.request("GET", path, check=200)
assert "ETag" in headers
assert headers["Content-Type"] == "text/calendar; charset=utf-8"
assert "VEVENT" in answer
assert "Event" in answer
assert "UID:event" in answer
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 "New event detected, sending notifications to all attendees: event1" in log]) == 1
assert len([log for log in logs if "Hello everyone" in log]) == 1
def test_add_event_with_future_mass2_end_date(self, caplog) -> None:
self.configure({"hook": {"type": "email",
"mass_email": "True",
"dryrun": "True"}})
caplog.set_level(logging.INFO)
"""Add an event."""
self.mkcalendar("/calendar.ics/")
event = get_file_content("event1a1.ics")
event = self._replace_end_date_in_event(event, self._future_date_timestamp())
path = "/calendar.ics/event1.ics"
self.put(path, event)
_, headers, answer = self.request("GET", path, check=200)
assert "ETag" in headers
assert headers["Content-Type"] == "text/calendar; charset=utf-8"
assert "VEVENT" in answer
assert "Event" in answer
assert "UID:event" in answer
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 "New event detected, sending notifications to all attendees: event1" in log]) == 1
assert len([log for log in logs if "Hello everyone" in log]) == 0