Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EqCYBhvTcdeCTUDX3RhWx9
29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
import os
|
|
from fastapi.testclient import TestClient
|
|
|
|
def _client(monkeypatch):
|
|
monkeypatch.setenv("INTERNAL_API_KEY", "SECRET")
|
|
import importlib
|
|
from app import auth as _a
|
|
importlib.reload(_a) # env 반영
|
|
from app.main import app
|
|
return TestClient(app)
|
|
|
|
def test_targets_requires_key(monkeypatch):
|
|
c = _client(monkeypatch)
|
|
# 헤더 없음 — FastAPI Header(...)는 dependency 실행 전 자체 검증하므로 422.
|
|
# image-lab/tests/test_internal_router.py의 동일 패턴과 일치(sibling 서비스 선례).
|
|
assert c.get("/api/internal/realestate/targets").status_code in (401, 422)
|
|
assert c.get("/api/internal/realestate/targets",
|
|
headers={"X-Internal-Key": "WRONG"}).status_code == 401
|
|
|
|
def test_targets_returns_dongs_with_cortar(monkeypatch):
|
|
c = _client(monkeypatch)
|
|
r = c.get("/api/internal/realestate/targets", headers={"X-Internal-Key": "SECRET"})
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
dongs = {d["dong"]: d["cortar_no"] for d in body["dongs"]}
|
|
assert dongs.get("신대방동") == "1159010100" # criteria seed 6동 + cortar join
|
|
assert "전세" in body["deal_types"]
|
|
assert isinstance(body["page_limit"], int)
|