Files
lingniu-vehicle-ingest/tools/test_go_native_prod_smoke.py
2026-07-02 01:34:28 +08:00

84 lines
2.8 KiB
Python

import datetime as dt
import unittest
from tools import go_native_prod_smoke as smoke
class GoNativeProdSmokeTest(unittest.TestCase):
def test_shanghai_day_window_uses_plus_eight_bounds(self):
now = dt.datetime(2026, 7, 2, 1, 35, tzinfo=smoke.SHANGHAI)
date_from, date_to = smoke.shanghai_day_window(now)
self.assertEqual(date_from, "2026-07-02T00:00:00+08:00")
self.assertEqual(date_to, "2026-07-03T00:00:00+08:00")
def test_api_url_encodes_plus_eight_date_range(self):
url = smoke.api_url(
"http://example.test/base/",
"/api/history/raw-frames",
{
"protocol": "JT808",
"dateFrom": "2026-07-02T00:00:00+08:00",
"dateTo": "2026-07-03T00:00:00+08:00",
"limit": 1,
},
)
self.assertEqual(
url,
"http://example.test/base/api/history/raw-frames?"
"protocol=JT808&dateFrom=2026-07-02T00%3A00%3A00%2B08%3A00"
"&dateTo=2026-07-03T00%3A00%3A00%2B08%3A00&limit=1",
)
def test_total_check_passes_when_total_reaches_minimum(self):
check = smoke.check_total(
"jt808.raw",
{"total": 2, "items": [{"vehicle_key": "JT808:013307811170"}]},
minimum=1,
)
self.assertEqual(check.status, "pass")
self.assertEqual(check.count, 2)
self.assertIn("JT808:013307811170", check.message)
def test_total_check_fails_when_total_is_below_minimum(self):
check = smoke.check_total("gb32960.raw", {"total": 0, "items": []}, minimum=1)
self.assertEqual(check.status, "fail")
self.assertEqual(check.count, 0)
self.assertIn("expected >= 1", check.message)
def test_overall_status_fails_if_any_check_fails(self):
checks = [
smoke.Check("a", "pass", 1, 1, "ok"),
smoke.Check("b", "fail", 0, 1, "bad"),
]
self.assertEqual(smoke.overall_status(checks), "fail")
def test_build_checks_cover_three_raw_protocols_and_two_daily_metric_protocols(self):
specs = smoke.build_check_specs(
date_from="2026-07-02T00:00:00+08:00",
date_to="2026-07-03T00:00:00+08:00",
stat_date="2026-07-02",
min_raw=1,
min_history=1,
min_stat=1,
)
names = [spec.name for spec in specs]
self.assertIn("gb32960.raw", names)
self.assertIn("jt808.raw", names)
self.assertIn("yutong_mqtt.raw", names)
self.assertIn("jt808.locations", names)
self.assertIn("jt808.mileage_points", names)
self.assertIn("gb32960.daily_mileage", names)
self.assertIn("jt808.daily_total_mileage", names)
if __name__ == "__main__":
unittest.main()