修正设备定位坐标系归一化
This commit is contained in:
51
talkingq-url/tests/test_location_coordinate_normalization.py
Normal file
51
talkingq-url/tests/test_location_coordinate_normalization.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import pytest
|
||||
|
||||
from banban.service.location import (
|
||||
LocationService,
|
||||
normalize_location_coordinate,
|
||||
)
|
||||
|
||||
|
||||
def test_normalize_default_device_location_from_wgs84_to_gcj02():
|
||||
lat, lng, coord_type = normalize_location_coordinate(
|
||||
latitude=30.223122166666666,
|
||||
longitude=120.25837883333334,
|
||||
coord_type=None,
|
||||
)
|
||||
|
||||
assert coord_type == "gcj02"
|
||||
assert lat == pytest.approx(30.22066658053894)
|
||||
assert lng == pytest.approx(120.26284572518867)
|
||||
|
||||
|
||||
def test_normalize_explicit_gcj02_does_not_convert_again():
|
||||
lat, lng, coord_type = normalize_location_coordinate(
|
||||
latitude=30.223122166666666,
|
||||
longitude=120.25837883333334,
|
||||
coord_type="gcj02",
|
||||
)
|
||||
|
||||
assert coord_type == "gcj02"
|
||||
assert lat == pytest.approx(30.223122166666666)
|
||||
assert lng == pytest.approx(120.25837883333334)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mqtt_location_report_ignores_zero_zero_before_normalization(monkeypatch):
|
||||
service = LocationService()
|
||||
sessions = []
|
||||
|
||||
async def fail_get_session():
|
||||
sessions.append("called")
|
||||
raise AssertionError("invalid location should not open a database session")
|
||||
|
||||
monkeypatch.setattr(service, "get_session", fail_get_session)
|
||||
|
||||
row = await service.report_mqtt_device_location(
|
||||
device_id="TalkingQ_device001",
|
||||
latitude=0,
|
||||
longitude=0,
|
||||
)
|
||||
|
||||
assert row is None
|
||||
assert sessions == []
|
||||
Reference in New Issue
Block a user