停止记录和补记值班缺勤,移除缺勤入口并保留历史数据

This commit is contained in:
2026-11-08 11:41:29 +08:00
parent 6377a42a8f
commit 0663b44cdc
10 changed files with 50 additions and 115 deletions
+15 -2
View File
@@ -4,12 +4,25 @@ import unittest
from contextlib import closing
from datetime import date, datetime
from pathlib import Path
from unittest.mock import AsyncMock
from unittest.mock import AsyncMock, patch
from server.duty import BEIJING, ROOT, duties_on, duty_status, load_schedule, resolve_recipients, send_due
from server.duty import BEIJING, ROOT, duties_on, duty_status, load_schedule, resolve_recipients, send_due, reminder_loop
class DutyTests(unittest.IsolatedAsyncioTestCase):
async def test_scheduler_never_creates_absences_after_shift_or_restart(self):
import server.duty as duty
accounts = AsyncMock(return_value=[])
send = AsyncMock()
with patch.object(duty, 'datetime', wraps=datetime) as clock, patch.object(duty.asyncio, 'sleep', new_callable=AsyncMock) as sleep:
clock.now.return_value = datetime(2026, 11, 6, 20, tzinfo=BEIJING)
sleep.side_effect = asyncio.CancelledError()
for _ in range(2):
with self.assertRaises(asyncio.CancelledError):
await reminder_loop(ROOT / 'duty/schedule.json', self.state, accounts, send)
self.assertFalse(self.state.exists())
send.assert_not_called()
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.state = Path(self.tmp.name) / "reminders.db"