mirror of
https://github.com/Kozea/Radicale.git
synced 2025-08-31 19:50:55 +00:00
- Fix unit tests for hook email trigger conditional based on end date
This commit is contained in:
parent
9b6ba72fa0
commit
998b2e2121
2 changed files with 29 additions and 28 deletions
|
@ -981,8 +981,11 @@ class Hook(BaseHook):
|
||||||
return
|
return
|
||||||
email_event_end_time = email_event_event.datetime_end # type: ignore
|
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.
|
# 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 < (
|
if email_event_end_time and email_event_end_time.time:
|
||||||
datetime.now() - timedelta(minutes=1)):
|
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",
|
logger.warning("Event end time is in the past, skipping notification for event: %s",
|
||||||
email_event_event.uid)
|
email_event_event.uid)
|
||||||
return
|
return
|
||||||
|
|
|
@ -93,16 +93,12 @@ permissions: RrWw""")
|
||||||
assert "VEVENT" in answer
|
assert "VEVENT" in answer
|
||||||
assert "Event" in answer
|
assert "Event" in answer
|
||||||
assert "UID:event" in answer
|
assert "UID:event" in answer
|
||||||
found = 0
|
|
||||||
for line in caplog.messages:
|
logs = caplog.messages
|
||||||
if line.find("notification_item: {'type': 'upsert'") != -1:
|
# Should have a log saying the notification item was received
|
||||||
found = found | 1
|
assert len([log for log in logs if "received notification_item: {'type': 'upsert'," in log]) == 1
|
||||||
if line.find("to_addresses=['janedoe@example.com']") != -1:
|
# Should NOT have a log saying that no email is sent (email won't actually be sent due to dryrun)
|
||||||
found = found | 2
|
assert len([log for log in logs if "skipping notification for event: event1" in log]) == 0
|
||||||
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)
|
|
||||||
|
|
||||||
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)
|
||||||
|
@ -119,8 +115,11 @@ permissions: RrWw""")
|
||||||
assert "Event" in answer
|
assert "Event" in answer
|
||||||
assert "UID:event" in answer
|
assert "UID:event" in answer
|
||||||
|
|
||||||
# Should not trigger an email
|
logs = caplog.messages
|
||||||
assert len(caplog.messages) == 0
|
# 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:
|
def test_delete_event_with_future_end_date(self, caplog) -> None:
|
||||||
caplog.set_level(logging.WARNING)
|
caplog.set_level(logging.WARNING)
|
||||||
|
@ -134,16 +133,12 @@ permissions: RrWw""")
|
||||||
assert responses[path] == 200
|
assert responses[path] == 200
|
||||||
_, answer = self.get("/calendar.ics/")
|
_, answer = self.get("/calendar.ics/")
|
||||||
assert "VEVENT" not in answer
|
assert "VEVENT" not in answer
|
||||||
found = 0
|
|
||||||
for line in caplog.messages:
|
logs = caplog.messages
|
||||||
if line.find("notification_item: {'type': 'delete'") != -1:
|
# Should have a log saying the notification item was received
|
||||||
found = found | 1
|
assert len([log for log in logs if "received notification_item: {'type': 'delete'," in log]) == 1
|
||||||
if line.find("to_addresses=['janedoe@example.com']") != -1:
|
# Should NOT have a log saying that no email is sent (email won't actually be sent due to dryrun)
|
||||||
found = found | 2
|
assert len([log for log in logs if "skipping notification for event: event1" in log]) == 0
|
||||||
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)
|
|
||||||
|
|
||||||
def test_delete_event_with_past_end_date(self, caplog) -> None:
|
def test_delete_event_with_past_end_date(self, caplog) -> None:
|
||||||
caplog.set_level(logging.WARNING)
|
caplog.set_level(logging.WARNING)
|
||||||
|
@ -158,5 +153,8 @@ permissions: RrWw""")
|
||||||
_, answer = self.get("/calendar.ics/")
|
_, answer = self.get("/calendar.ics/")
|
||||||
assert "VEVENT" not in answer
|
assert "VEVENT" not in answer
|
||||||
|
|
||||||
# Should not trigger an email
|
logs = caplog.messages
|
||||||
assert len(caplog.messages) == 0
|
# 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue