feat: 增加日历与版本化日报
This commit is contained in:
63
tests/test_calendar.py
Normal file
63
tests/test_calendar.py
Normal file
@ -0,0 +1,63 @@
|
||||
from datetime import date
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from snooper_calendar import fetch_calendar_events
|
||||
|
||||
|
||||
class FakeCalendarClient:
|
||||
def __init__(self):
|
||||
self.calls = []
|
||||
|
||||
def api(self, name, data):
|
||||
self.calls.append((name, data))
|
||||
if name == "calendars.GetUserPrimaryCalendarRequest":
|
||||
return {"calendar": {"id": "calendar-synthetic"}}
|
||||
assert name == "calendarevents.QueryInstanceRequest"
|
||||
return {
|
||||
"calendarEventInstance": [
|
||||
{
|
||||
"eventRefId": "event-b",
|
||||
"beginTime": 1_789_000_000,
|
||||
"endTime": 1_789_003_600,
|
||||
},
|
||||
{
|
||||
"eventRefId": "event-a",
|
||||
"beginTime": 1_788_000_000,
|
||||
"endTime": 1_788_003_600,
|
||||
},
|
||||
],
|
||||
"events": {
|
||||
"event-a": {
|
||||
"summary": "合成早会",
|
||||
"locations": [{"name": "合成会议室 A"}],
|
||||
"isDeleted": False,
|
||||
"url": "https://example.com/a",
|
||||
},
|
||||
"event-b": {
|
||||
"summary": "合成下午会",
|
||||
"locations": [{"name": "合成会议室 B"}],
|
||||
"isDeleted": True,
|
||||
"meetingMinuteUrl": "https://example.com/minutes-b",
|
||||
"url": "https://example.com/event-b",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_fetch_calendar_events_normalizes_and_sorts_daily_instances():
|
||||
client = FakeCalendarClient()
|
||||
tz = ZoneInfo("Asia/Shanghai")
|
||||
|
||||
events = fetch_calendar_events(client, date(2026, 9, 9), tz)
|
||||
|
||||
assert [event["summary"] for event in events] == ["合成早会", "合成下午会"]
|
||||
assert events[0]["location"] == "合成会议室 A"
|
||||
assert events[0]["url"] == "https://example.com/a"
|
||||
assert events[1]["cancelled"] is True
|
||||
assert events[1]["url"] == "https://example.com/minutes-b"
|
||||
assert "attendees" not in events[0]
|
||||
assert "description" not in events[0]
|
||||
name, request = client.calls[1]
|
||||
assert request["calendarIds"] == ["calendar-synthetic"]
|
||||
assert request["needsBriefEvents"] is True
|
||||
assert request["endTime"] - request["startTime"] == 86_400
|
||||
Reference in New Issue
Block a user