56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
from datetime import UTC, date, datetime
|
|
|
|
from app.services.caldav import CaldavEventCache
|
|
|
|
|
|
def create_cache():
|
|
"""Create the instance without calling __init__, so tests need no CalDAV server."""
|
|
cache = CaldavEventCache.__new__(CaldavEventCache)
|
|
cache.events = [
|
|
{
|
|
"uid": "1",
|
|
"summary": "Timed event",
|
|
"groups": ["team-a", "shared"],
|
|
"start": datetime(2026, 11, 2, 10, 0, tzinfo=UTC),
|
|
"end": datetime(2026, 11, 2, 11, 0, tzinfo=UTC),
|
|
"all_day": False,
|
|
},
|
|
{
|
|
"uid": "2",
|
|
"summary": "All-day event",
|
|
"groups": ["team-b", "shared"],
|
|
"start": date(2026, 11, 2),
|
|
"end": date(2026, 11, 3), # Exclusive end date
|
|
"all_day": True,
|
|
},
|
|
]
|
|
return cache
|
|
|
|
|
|
def test_active_during_timed_event():
|
|
cache = create_cache()
|
|
during_event = datetime(2026, 11, 2, 10, 30, tzinfo=UTC)
|
|
assert cache.is_group_active("team-a", during_event)
|
|
assert cache.is_group_active("shared", during_event)
|
|
assert cache.is_group_active("team-b", during_event) # warum 'not'?
|
|
|
|
|
|
def test_timed_event_end_exclusive():
|
|
cache = create_cache()
|
|
at_timed_event_end = datetime(2026, 11, 2, 11, 0, tzinfo=UTC)
|
|
assert not cache.is_group_active("team-a", at_timed_event_end)
|
|
assert cache.is_group_active("team-b", at_timed_event_end)
|
|
assert cache.is_group_active("shared", at_timed_event_end)
|
|
|
|
|
|
def test_unknown_group():
|
|
cache = create_cache()
|
|
during_event = datetime(2026, 11, 2, 10, 30, tzinfo=UTC)
|
|
assert not cache.is_group_active("unknown", during_event)
|
|
|
|
|
|
def test_all_day_event_exclusive():
|
|
cache = create_cache()
|
|
next_day = datetime(2026, 11, 3, 9, 0, tzinfo=UTC)
|
|
assert not cache.is_group_active("team-b", next_day)
|