tracksolid_timescale_grafan.../tests/fixtures/api_responses.py
David Kiania 6ed4d3a1e2 test: add test suite - unit tests, webhook endpoint tests, and CI workflow
57 unit tests covering clean helpers, API signing, and field mapping fixes
(FIX-E06, FIX-M16, BUG-01, BUG-03); integration tests for webhook endpoints
with mocked DB; Forgejo CI workflow with TimescaleDB service container.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 21:38:20 +03:00

109 lines
3 KiB
Python

"""Mock Tracksolid Pro API responses for testing."""
# jimi.user.device.location.list response
LIVE_POSITIONS_RESPONSE = {
"code": 0,
"result": [
{
"imei": "123456789012345",
"lat": -1.2921,
"lng": 36.8219,
"speed": 45.5,
"direction": 180,
"gpsTime": "2024-04-12 08:00:00",
"hbTime": "2024-04-12 08:00:05",
"accStatus": "1",
"gpsSignal": 4,
"gpsNum": 8,
"currentMileage": 1234.5,
"posType": "GPS",
"confidence": 95,
"status": "1",
"locDesc": "Nairobi CBD",
},
{
# Zero Island — should be filtered by is_valid_fix
"imei": "999999999999999",
"lat": 0.0,
"lng": 0.0,
"speed": 0,
"gpsTime": "2024-04-12 08:00:00",
},
]
}
# jimi.device.track.mileage response (distance in METRES — FIX-M16)
TRIPS_RESPONSE = {
"code": 0,
"result": [
{
"imei": "123456789012345",
"startTime": "2024-04-12 07:00:00",
"endTime": "2024-04-12 08:00:00",
"distance": 15000, # 15000 METRES = 15.0 km
"avgSpeed": 15.0,
"maxSpeed": 60.0,
"runTimeSecond": 3600,
}
]
}
# jimi.device.alarm.list response (FIX-E06: uses alertTypeId, not alarmType)
ALARMS_RESPONSE = {
"code": 0,
"result": [
{
"imei": "123456789012345",
"alertTypeId": "4", # poll field name
"alarmTypeName": "Speeding", # poll field name
"alertTime": "2024-04-12 07:30:00", # poll field name
"lat": -1.2921,
"lng": 36.8219,
"speed": 95.0,
"accStatus": "1",
}
]
}
# Webhook /pushalarm payload (uses alarmType, not alertTypeId)
WEBHOOK_ALARM_PAYLOAD = {
"deviceImei": "123456789012345",
"alarmType": "4",
"alarmName": "Speeding",
"gateTime": "2024-04-12 07:30:00",
"lat": -1.2921,
"lng": 36.8219,
"speed": 95.0,
}
# Webhook /pushtripreport payload (BCD timestamp — BUG-03)
WEBHOOK_TRIP_BCD_PAYLOAD = {
"deviceImei": "123456789012345",
"beginTime": "220415103000", # BCD YYMMDDHHmmss = 2022-04-15 10:30:00
"endTime": "220415113000", # BCD YYMMDDHHmmss = 2022-04-15 11:30:00
"miles": 12.5,
"beginLat": -1.2921,
"beginLng": 36.8219,
"endLat": -1.3000,
"endLng": 36.8300,
}
WEBHOOK_TRIP_ISO_PAYLOAD = {
"deviceImei": "123456789012345",
"beginTime": "2024-04-12 07:00:00",
"endTime": "2024-04-12 08:00:00",
"miles": 15.5,
}
# Webhook /pushobd payload
WEBHOOK_OBD_PAYLOAD = {
"deviceImei": "123456789012345",
"obdJson": '{"event_time": 1712908800, "AccState": 1, "statusFlags": 0, "lat": -1.2921, "lng": 36.8219}',
}
# Alarm with NULL alarm_type (BUG-02 guard)
WEBHOOK_ALARM_NULL_TYPE = {
"deviceImei": "123456789012345",
"alarmType": None,
"gateTime": "2024-04-12 07:30:00",
}