import pytest from httpx import ASGITransport, AsyncClient from router.router import app async def _get(path: str, **params): async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: return (await client.get(path, params=params)).json() @pytest.mark.anyio async def test_region_list_has_all_256_districts(): body = await _get("/v1/region/list") assert body["result"]["success"] is True assert len(body["regions"]) == 256 @pytest.mark.anyio async def test_region_search_by_name(): body = await _get("/v1/region/list", q="마포") assert [r["name"] for r in body["regions"]] == ["서울 마포구"] @pytest.mark.anyio async def test_nearest_from_mangwon_park_is_mapo(): body = await _get("/v1/region/nearest", lat=37.5555, lon=126.8950) assert body["region"]["name"] == "서울 마포구" @pytest.mark.anyio async def test_nearest_rejects_point_outside_korea(): async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: res = await client.get("/v1/region/nearest", params={"lat": 10, "lon": 127}) assert res.status_code == 422 @pytest.mark.anyio async def test_enum_query_param_accepts_numeric_string(): async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: res = await client.get("/v1/season/article/list", params={"category": "2"}) assert res.status_code == 200 and all(a["category"] == 2 for a in res.json()["articles"])