"""매일 하는 업무(033 tasks.repeat_daily) 알림 — 시각 고르기·수신자·중복. DB 없이 가짜 저장소로. 실제 DB(열·update_task 규칙)는 tests/test_project_module.py test_repeat_daily_* 가 본다. """ import importlib import unittest from datetime import date from unittest.mock import patch rem = importlib.import_module("app.modules.project.reminders") class FakeStore: def __init__(self, tasks): self.tasks = tasks self.sent = set() self.made = [] def list_open_daily_tasks(self): return list(self.tasks) def add_reminder_notification(self, **kw): key = (kw["task_id"], kw["kind"], kw["due_date"], kw["recipient_email"]) if key in self.sent: return False self.sent.add(key) self.made.append(kw) return True def _visible(st, task, wanted, lookup=None): return [e for e in wanted if e != "gone@x.kr"] # 권한 잃은 사람은 뺀다 class DailyAlertTests(unittest.TestCase): def test_slot_is_latest_passed_time(self): self.assertIsNone(rem.daily_slot(["09:00", "14:00"], "08:59")) self.assertEqual(rem.daily_slot(["09:00", "14:00"], "09:00"), "09:00") self.assertEqual(rem.daily_slot(["09:00", "14:00"], "23:59"), "14:00") self.assertIsNone(rem.daily_slot([], "12:00")) def test_assignee_else_followers_once_per_slot(self): st = FakeStore([ {"id": 1, "title": "청소", "assignee_email": "A@x.kr", "followers": ["b@x.kr"], "project_id": 7, "project_name": "P"}, {"id": 2, "title": "보고", "assignee_email": "", "followers": ["b@x.kr", "gone@x.kr"], "project_id": 7}, ]) with patch.object(rem.access, "filter_recipients", side_effect=_visible): self.assertEqual(rem.run_daily_alerts(st, today=date(2026, 11, 11), slot="09:00"), 2) self.assertEqual(rem.run_daily_alerts(st, today=date(2026, 11, 11), slot="09:00"), 0) # 같은 시각은 한 번 self.assertEqual(rem.run_daily_alerts(st, today=date(2026, 11, 11), slot="14:00"), 2) # 다음 시각은 또 first = st.made[0] self.assertEqual((first["recipient_email"], first["kind"], first["ntype"]), ("a@x.kr", "daily@09:00", "daily")) self.assertEqual(first["title"], "매일 업무: 청소") self.assertEqual({m["recipient_email"] for m in st.made if m["task_id"] == 2}, {"b@x.kr"}) def test_daily_is_popup_alert_type(self): api = importlib.import_module("app.modules.project.router") self.assertIn("daily", api._ALERT_TYPES) if __name__ == "__main__": unittest.main()