42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import contextlib
|
|
import io
|
|
import json
|
|
import unittest
|
|
from datetime import datetime
|
|
|
|
import logwatch
|
|
|
|
|
|
class LogwatchDateTests(unittest.TestCase):
|
|
def test_overnight_session_silent_alert_uses_current_event_date(self):
|
|
config = {
|
|
"webhook_url": "",
|
|
"orb_window_start": "09:30",
|
|
"orb_window_end": "10:15",
|
|
"timezone": "America/New_York",
|
|
"events": {"silent_window_alert": True, "connection": True, "session_start": True},
|
|
}
|
|
state = logwatch.WatchState()
|
|
state.session_date = datetime(2026, 8, 13, 17, 26, 24).date()
|
|
state.event_date = state.session_date
|
|
|
|
with contextlib.redirect_stdout(io.StringIO()):
|
|
logwatch.handle_line(config, True, state, "[17:26:24.803] === SESSION START 2026-08-13 17:26:24 ===")
|
|
logwatch.handle_line(config, True, state, "[17:26:24.803] Account : SimSimple ORB")
|
|
logwatch.handle_line(config, True, state, "[08:23:20.300] CONNECTION LOST at 08:23:20 Status=ConnectionLost")
|
|
|
|
self.assertEqual(datetime(2026, 8, 14).date(), state.event_date)
|
|
|
|
output = io.StringIO()
|
|
with contextlib.redirect_stdout(output):
|
|
logwatch.check_silent_window(config, True, state, datetime(2026, 8, 14, 10, 16, 0))
|
|
|
|
payload = json.loads(output.getvalue().strip())
|
|
self.assertEqual("SILENT WINDOW ALERT", payload["event_type"])
|
|
self.assertEqual("2026-08-14", payload["session_date"])
|
|
self.assertEqual("2026-08-14", payload["event_date"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|