- /api/map/search?q= — VWorld 주소(도로명 → 지번) 먼저 · 장소(POI) 뒤 · 같은 이름 · 주소 줄 하나 · 키는 서버 · 실패 = 빈 목록 - B01_Dashboard_Map.search_place 더함(있는 search_address 그대로) - 시험 594_4 새로(VWorld 가짜) · 563_2 붙인 선 이름 = 조각 이름표 · zip 폴더 · 좌표표 xlsx 「선」 칸 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
"""594-4 공용 주소 · 장소 찾기 길(`GET /api/map/search`) — VWorld 가짜 응답.
|
|
|
|
- 주소(도로명 → 지번) 먼저 · 장소 뒤 · 같은 이름 · 주소 줄 하나 · 키는 서버(응답에 없음).
|
|
- 빈 값 = 빈 목록 · 100 자 넘음 = 422 · VWorld 실패 = 빈 목록.
|
|
|
|
./venv/Scripts/python.exe -m pytest resources/tester/test_594_4_map_search.py -q
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from urllib.parse import parse_qs, urlparse
|
|
|
|
import pytest
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
from B01_Dashboard import B01_Dashboard_Map as vmap
|
|
from common_util import common_util_map_router as map_router
|
|
|
|
ADDRESS = {
|
|
"address": {"zipcode": "36509", "road": "", "parcel": "경상북도 영양군 일월면 용화리 1"},
|
|
"point": {"x": "129.165", "y": "36.815"},
|
|
}
|
|
PLACE = {
|
|
"title": "용화보건진료소",
|
|
"address": {"road": "경상북도 영양군 일월면 영양로 3773", "parcel": "… 용화리 225-1"},
|
|
"point": {"x": "129.150", "y": "36.789"},
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def api(monkeypatch):
|
|
asked = []
|
|
|
|
def fetch(url, timeout=5):
|
|
query = {k: v[0] for k, v in parse_qs(urlparse(url).query).items()}
|
|
asked.append(query)
|
|
if query.get("query") == "고장":
|
|
raise OSError("down")
|
|
if query["type"] == "address":
|
|
items = [ADDRESS] if query["category"] == "parcel" else []
|
|
else:
|
|
items = [PLACE, PLACE] # VWorld 가 같은 장소를 두 번 줌
|
|
return json.dumps({"response": {"status": "OK", "result": {"items": items}}}).encode()
|
|
|
|
monkeypatch.setattr(vmap, "_fetch", fetch)
|
|
app = FastAPI()
|
|
app.include_router(map_router.router)
|
|
client = TestClient(app)
|
|
client.asked = asked
|
|
return client
|
|
|
|
|
|
def test_address_then_place(api) -> None:
|
|
got = api.get("/api/map/search", params={"q": " 용화리 "})
|
|
assert got.status_code == 200
|
|
items = got.json()["items"]
|
|
assert items == [
|
|
{
|
|
"kind": "address",
|
|
"title": "경상북도 영양군 일월면 용화리 1",
|
|
"address": "",
|
|
"lon": 129.165,
|
|
"lat": 36.815,
|
|
},
|
|
{
|
|
"kind": "place",
|
|
"title": "용화보건진료소",
|
|
"address": "경상북도 영양군 일월면 영양로 3773",
|
|
"lon": 129.15,
|
|
"lat": 36.789,
|
|
},
|
|
]
|
|
assert {q["query"] for q in api.asked} == {"용화리"} # 앞뒤 빈칸 뺌
|
|
assert "key" not in got.text # 키는 서버만
|
|
|
|
|
|
def test_empty_long_and_failure(api) -> None:
|
|
assert api.get("/api/map/search", params={"q": " "}).json()["items"] == []
|
|
assert api.get("/api/map/search", params={"q": "가" * 101}).status_code == 422
|
|
assert api.get("/api/map/search", params={"q": "고장"}).json()["items"] == []
|