test: add live ingest verification gate
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was canceled
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was canceled
This commit is contained in:
72
tools/test_vehicle_ingest_live_verify.py
Normal file
72
tools/test_vehicle_ingest_live_verify.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import unittest
|
||||
|
||||
from tools import vehicle_ingest_live_verify as live_verify
|
||||
|
||||
|
||||
class VehicleIngestLiveVerifyTest(unittest.TestCase):
|
||||
def test_warns_when_formal_gb32960_platform_login_exists_without_vehicle_frames(self):
|
||||
checks = live_verify.evaluate_counts(
|
||||
{
|
||||
"jt808RawFrames": 36090,
|
||||
"jt808Locations": 8783,
|
||||
"gb32960PlatformLogins": 3,
|
||||
"gb32960VehicleRealtimeFrames": 0,
|
||||
},
|
||||
live_verify.Thresholds(
|
||||
min_jt808_raw_frames=1,
|
||||
min_jt808_locations=1,
|
||||
min_gb32960_platform_logins=1,
|
||||
min_gb32960_vehicle_realtime_frames=1,
|
||||
require_gb32960_vehicle_realtime=False,
|
||||
),
|
||||
)
|
||||
|
||||
by_name = {check.name: check for check in checks}
|
||||
|
||||
self.assertEqual(live_verify.overall_status(checks), "warn")
|
||||
self.assertEqual(by_name["gb32960.vehicle_realtime"].status, "warn")
|
||||
self.assertIn("尚未收到正式车辆 0x02", by_name["gb32960.vehicle_realtime"].message)
|
||||
|
||||
def test_fails_when_vehicle_frames_are_required_but_missing(self):
|
||||
checks = live_verify.evaluate_counts(
|
||||
{
|
||||
"jt808RawFrames": 10,
|
||||
"jt808Locations": 2,
|
||||
"gb32960PlatformLogins": 1,
|
||||
"gb32960VehicleRealtimeFrames": 0,
|
||||
},
|
||||
live_verify.Thresholds(require_gb32960_vehicle_realtime=True),
|
||||
)
|
||||
|
||||
by_name = {check.name: check for check in checks}
|
||||
|
||||
self.assertEqual(live_verify.overall_status(checks), "fail")
|
||||
self.assertEqual(by_name["gb32960.vehicle_realtime"].status, "fail")
|
||||
|
||||
def test_gb32960_vehicle_realtime_sql_excludes_test_vins(self):
|
||||
sql = live_verify.gb32960_vehicle_realtime_count_sql(
|
||||
date_from="2026-06-29 00:00:00",
|
||||
date_to="2026-06-29 23:59:59",
|
||||
)
|
||||
|
||||
self.assertIn("message_id = 2", sql)
|
||||
self.assertIn("vin <> ''", sql)
|
||||
self.assertIn("vin NOT LIKE 'LTEST%'", sql)
|
||||
self.assertIn("ts >= '2026-06-29 00:00:00'", sql)
|
||||
self.assertIn("ts <= '2026-06-29 23:59:59'", sql)
|
||||
|
||||
def test_jt808_location_sql_uses_dedicated_location_stable_without_protocol_filter(self):
|
||||
sql = live_verify.jt808_location_count_sql(
|
||||
date_from="2026-06-29 00:00:00",
|
||||
date_to="2026-06-29 23:59:59",
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
sql,
|
||||
"SELECT COUNT(*) FROM jt808_locations WHERE "
|
||||
"ts >= '2026-06-29 00:00:00' AND ts <= '2026-06-29 23:59:59'",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user