fix: bind knowledge maps to explicit regions

This commit is contained in:
xuelong committed 2026-08-26 02:26:24 -07:00
1 parent 329a94d457
commit 90f75d41ae
15 files changed
+1126 -275

No files matched your search

+80 -3
View File
@@ -111,15 +111,92 @@ class ProjectPayloadValidationTests(unittest.TestCase):
def test_spatial_map_defaults_to_disabled_libo_scope(self) -> None:
payload = normalize_provision_payload(valid_payload())
self.assertEqual(payload["spatial_map"], {"enabled": False, "scope": "libo"})
self.assertEqual(payload["spatial_map"], {
"enabled": False,
"scope": "libo",
"region_name": "",
"region_adcode": "",
"region_level": "province",
})
def test_spatial_map_option_is_normalized(self) -> None:
body = valid_payload()
body["spatial_map"] = {"enabled": True, "scope": "guizhou"}
body["schema"]["entity_types"]["Place"]["fields"].update({
"lng": {"type": "number"},
"lat": {"type": "number"},
"adcode": {"type": "string"},
"place_type": {"type": "string"},
})
body["graph_data"]["nodes"][0]["properties"].update({
"lng": 106.63,
"lat": 26.65,
"adcode": "520102",
"place_type": "mall",
})
body["spatial_map"] = {
"enabled": True,
"scope": "guizhou",
"region_name": "贵阳市",
"region_adcode": "520100",
"region_level": "city",
}
payload = normalize_provision_payload(body)
self.assertEqual(payload["spatial_map"], {"enabled": True, "scope": "guizhou"})
self.assertEqual(payload["spatial_map"], body["spatial_map"])
def test_spatial_map_rejects_data_outside_selected_city(self) -> None:
body = valid_payload()
body["schema"]["entity_types"]["Place"]["fields"].update({
"lng": {"type": "number"},
"lat": {"type": "number"},
"adcode": {"type": "string"},
"type_label": {"type": "string"},
})
body["graph_data"]["nodes"][0]["properties"].update({
"lng": 107.0,
"lat": 27.0,
"adcode": "520302",
"type_label": "美食",
})
body["spatial_map"] = {
"enabled": True,
"scope": "guizhou",
"region_name": "贵阳市",
"region_adcode": "520100",
"region_level": "city",
}
with self.assertRaises(ProjectValidationError) as raised:
normalize_provision_payload(body)
self.assertIn("数据与所选区域 贵阳市 不一致", ";".join(raised.exception.errors))
def test_spatial_map_accepts_legacy_city_name_when_adcode_is_missing(self) -> None:
body = valid_payload()
body["schema"]["entity_types"]["Place"]["fields"].update({
"lng": {"type": "number"},
"lat": {"type": "number"},
"city": {"type": "string"},
"place_type": {"type": "string"},
})
body["graph_data"]["nodes"][0]["properties"].update({
"lng": 106.63,
"lat": 26.65,
"city": "贵阳",
"place_type": "transit_stop",
})
body["spatial_map"] = {
"enabled": True,
"scope": "guizhou",
"region_name": "贵阳市",
"region_adcode": "520100",
"region_level": "city",
}
payload = normalize_provision_payload(body)
self.assertEqual(payload["spatial_map"]["region_name"], "贵阳市")
def test_invalid_spatial_map_is_rejected(self) -> None:
body = valid_payload()