Repository navigation
Expand file tree
/
Copy pathtest_programme_notifications_cog.py
More file actions
104 lines (81 loc) · 2.37 KB
/
Copy pathtest_programme_notifications_cog.py
File metadata and controls
104 lines (81 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from datetime import UTC, datetime
from types import SimpleNamespace
from unittest.mock import AsyncMock
from discord import channel
import pytest
from europython_discord.programme_notifications.cog import (
ProgrammeNotificationsCog,
_format_schedule_change,
)
from europython_discord.programme_notifications.models import (
ScheduleChange,
Session,
)
@pytest.mark.asyncio
async def test_fetch_schedule_detects_changes(caplog):
caplog.set_level("INFO")
cog = object.__new__(ProgrammeNotificationsCog)
cog.programme_connector = AsyncMock()
cog.bot = SimpleNamespace()
cog.config = SimpleNamespace(
schedule_updates_channel_name="schedule-updates"
)
channel = AsyncMock()
channel.name = "schedule-updates"
cog.bot.get_all_channels = lambda: [channel]
old_session = Session(
event_type="session",
code="ABC123",
slug="test-session",
title="Old Title",
session_type="talk",
speakers=[],
tweet="",
level="beginner",
track=None,
rooms=["S1"],
start=datetime.now(tz=UTC),
website_url="",
duration=30,
)
new_session = old_session.model_copy(
update={"title": "New Title"}
)
change = ScheduleChange(
old_session=old_session,
new_session=new_session,
)
cog.programme_connector.fetch_schedule.return_value = [change]
await cog.fetch_schedule.coro(cog)
assert "Found 1 schedule changes." in caplog.text
channel.send.assert_called_once()
def test_format_schedule_change():
old_session = Session(
event_type="session",
code="ABC123",
slug="test-session",
title="Old Title",
session_type="talk",
speakers=[],
tweet="",
level="beginner",
track=None,
rooms=["S1"],
start=datetime(2026, 7, 28, 10, 0, tzinfo=UTC),
website_url="",
duration=30,
)
new_session = old_session.model_copy(
update={
"rooms": ["S2"],
"duration": 45,
}
)
change = ScheduleChange(
old_session=old_session,
new_session=new_session,
)
message = _format_schedule_change(change)
assert "Schedule update: Old Title" in message
assert "Room changed: ['S1'] → ['S2']" in message
assert "Duration changed: 30 → 45 minutes" in message