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

- Add unit tests to confirm emails not triggered when adding/deleting event with past end date

This commit is contained in:
Nate Harris 2025-08-14 00:06:55 -06:00
parent 208dd22a42
commit f32e50bc9d
2 changed files with 55 additions and 4 deletions

View file

@ -300,8 +300,7 @@ class BaseStorage:
def discover(
self, path: str, depth: str = "0",
child_context_manager: Optional[
Callable[[str, Optional[str]], ContextManager[None]]] = None,
child_context_manager: Optional[Callable[[str, Optional[str]], ContextManager[None]]] = None,
user_groups: Set[str] = set([])) -> Iterable["types.CollectionOrItem"]:
"""Discover a list of collections under the given ``path``.

View file

@ -21,6 +21,8 @@ Radicale tests related to hook 'email'
import logging
import os
import re
from datetime import datetime, timedelta
from radicale.tests import BaseTest
from radicale.tests.helpers import get_file_content
@ -63,11 +65,26 @@ permissions: RrWw""")
self.configure({"hook": {"type": "email",
"dryrun": "True"}})
def test_add_event(self, caplog) -> None:
def _future_date_timestamp(self) -> str:
"""Return a date timestamp for a future date."""
future_date = datetime.now() + timedelta(days=1)
return future_date.strftime("%Y%m%dT%H%M%S")
def _past_date_timestamp(self) -> str:
past_date = datetime.now() - timedelta(days=1)
return past_date.strftime("%Y%m%dT%H%M%S")
def _replace_end_date_in_event(self, event: str, new_date: str) -> str:
"""Replace the end date in an event string."""
return re.sub(r"DTEND;TZID=Europe/Paris:\d{8}T\d{6}",
f"DTEND;TZID=Europe/Paris:{new_date}", event)
def test_add_event_with_future_end_date(self, caplog) -> None:
caplog.set_level(logging.WARNING)
"""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)
@ -87,11 +104,30 @@ permissions: RrWw""")
if (found != 7):
raise ValueError("Logging misses expected log lines, found=%d", found)
def test_delete_event(self, caplog) -> None:
def test_add_event_with_past_end_date(self, caplog) -> None:
caplog.set_level(logging.WARNING)
"""Add an event."""
self.mkcalendar("/calendar.ics/")
event = get_file_content("event1.ics")
event = self._replace_end_date_in_event(event, self._past_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
# Should not trigger an email
assert len(caplog.messages) == 0
def test_delete_event_with_future_end_date(self, caplog) -> None:
caplog.set_level(logging.WARNING)
"""Delete 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)
_, responses = self.delete(path)
@ -108,3 +144,19 @@ permissions: RrWw""")
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:
caplog.set_level(logging.WARNING)
"""Delete an event."""
self.mkcalendar("/calendar.ics/")
event = get_file_content("event1.ics")
event = self._replace_end_date_in_event(event, self._past_date_timestamp())
path = "/calendar.ics/event1.ics"
self.put(path, event)
_, responses = self.delete(path)
assert responses[path] == 200
_, answer = self.get("/calendar.ics/")
assert "VEVENT" not in answer
# Should not trigger an email
assert len(caplog.messages) == 0