feat(map): derive station regions from GPS
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -59,5 +60,30 @@ class DashboardTest(unittest.TestCase):
|
||||
self.assertEqual(calls, ["load"])
|
||||
self.assertEqual(first, second)
|
||||
|
||||
def test_station_region_comes_from_gps_reverse_geocode_and_persists_by_coordinate(self):
|
||||
station = {
|
||||
"longitude": 113.200001,
|
||||
"latitude": 23.100001,
|
||||
"province": "错误省份",
|
||||
"city": "错误城市",
|
||||
"district": "错误区县",
|
||||
}
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
cache_path = Path(directory) / "station-geocode.json"
|
||||
with patch.object(server, "STATION_GEOCODE_CACHE_PATH", cache_path), \
|
||||
patch.object(server, "_station_geocode_cache", None), \
|
||||
patch.object(server, "_station_geocode_cache_dirty", False), \
|
||||
patch.object(server, "_reverse_geocode_station", return_value={
|
||||
"province": "广东省", "city": "广州市", "district": "黄埔区", "adcode": "440112"
|
||||
}) as reverse:
|
||||
first = server._stations_with_gps_regions([station])[0]
|
||||
second = server._stations_with_gps_regions([dict(station, province="仍然错误")])[0]
|
||||
self.assertEqual(first["province"], "广东省")
|
||||
self.assertEqual(first["city"], "广州市")
|
||||
self.assertEqual(first["district"], "黄埔区")
|
||||
self.assertEqual(second["province"], "广东省")
|
||||
self.assertEqual(reverse.call_count, 1)
|
||||
self.assertTrue(cache_path.exists())
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user