feat: throttle no-change notifications daily
This commit is contained in:
@@ -203,6 +203,35 @@ class TicketingStateTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual(ticketing.load_tickets_state(state_path), expected_state)
|
||||
|
||||
def test_should_send_notification_always_sends_when_tickets_changed(self):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
state_path = os.path.join(tmpdir, "no_change_notification_state.json")
|
||||
ticket = {"id": 42, "write_date": "2026-07-24 12:00:00"}
|
||||
|
||||
self.assertTrue(ticketing.should_send_notification([ticket], state_path))
|
||||
|
||||
@patch("ticketing_setup.get_today", return_value="2026-07-27")
|
||||
def test_should_send_no_change_notification_once_per_day(self, get_today):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
state_path = os.path.join(tmpdir, "no_change_notification_state.json")
|
||||
|
||||
self.assertTrue(ticketing.should_send_notification([], state_path))
|
||||
|
||||
ticketing.record_no_change_notification(state_path)
|
||||
|
||||
self.assertFalse(ticketing.should_send_notification([], state_path))
|
||||
get_today.assert_called()
|
||||
|
||||
@patch("ticketing_setup.get_today", return_value="2026-07-28")
|
||||
def test_should_send_no_change_notification_again_next_day(self, get_today):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
state_path = os.path.join(tmpdir, "no_change_notification_state.json")
|
||||
ticketing.save_json_state(state_path, {
|
||||
"last_no_change_notification_date": "2026-07-27",
|
||||
})
|
||||
|
||||
self.assertTrue(ticketing.should_send_notification([], state_path))
|
||||
|
||||
@patch("ticketing_setup.requests.post")
|
||||
def test_fetch_odoo_tickets_authenticates_and_returns_result(self, post):
|
||||
auth_response = Mock()
|
||||
|
||||
Reference in New Issue
Block a user