40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
from datetime import datetime, timedelta
|
|
|
|
from banban.routers.devices import _row_to_alarm_item
|
|
|
|
|
|
def _alarm_row(created_at: datetime, location_updated_at: datetime):
|
|
return {
|
|
"alarm_id": 1,
|
|
"device_id": "TalkingQ_device001",
|
|
"child_id": 2,
|
|
"child_name": "测试孩子",
|
|
"source_msg_id": "010",
|
|
"coord_type": "gcj02",
|
|
"lat": 30.245,
|
|
"lng": 120.215,
|
|
"location_updated_at": location_updated_at,
|
|
"address": "浙江省杭州市上城区四季青街道剧院路杭州大剧院",
|
|
"address_resolved_at": location_updated_at,
|
|
"address_resolve_status": 1,
|
|
"created_at": created_at,
|
|
}
|
|
|
|
|
|
def test_alarm_location_updated_after_alarm_is_not_stale():
|
|
created_at = datetime(2026, 6, 8, 13, 56, 24)
|
|
row = _alarm_row(created_at, created_at + timedelta(seconds=2))
|
|
|
|
item = _row_to_alarm_item(row)
|
|
|
|
assert item.location_stale is False
|
|
|
|
|
|
def test_alarm_location_far_from_alarm_time_is_stale():
|
|
created_at = datetime(2026, 6, 8, 13, 56, 24)
|
|
row = _alarm_row(created_at, created_at - timedelta(minutes=20))
|
|
|
|
item = _row_to_alarm_item(row)
|
|
|
|
assert item.location_stale is True
|