- get_market_deals_for에 optional conn 파라미터 추가(재사용 시 open/close 안 함, 기존 단건 호출부는 불변) - bulk_upsert_listing_matches 추가(listing_matches 다건 upsert, 단일 connection) - run_listing_matching이 listings 조회+매물별 market_deals 조회+최종 upsert를 단일 _conn()으로 처리 (기존: 269건 매물마다 개별 _conn() 3회 → 병목) - POST /api/realestate/listings/rematch: MOLIT 재수집 없이 기존 listings+market_deals로 즉시 재판정 (알림 미발송, 즉시 피드백용) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EqCYBhvTcdeCTUDX3RhWx9
59 lines
2.8 KiB
Python
59 lines
2.8 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
def _client():
|
|
from app.main import app
|
|
return TestClient(app)
|
|
|
|
def test_criteria_get_default_and_put():
|
|
c = _client()
|
|
assert c.get("/api/realestate/listings/criteria").json()["max_deposit"] == 32000
|
|
c.put("/api/realestate/listings/criteria", json={"max_deposit": 30000})
|
|
assert c.get("/api/realestate/listings/criteria").json()["max_deposit"] == 30000
|
|
|
|
def test_budget_endpoint():
|
|
r = _client().post("/api/realestate/budget", json={"equity": 30000, "annual_income": 8000,
|
|
"is_homeless": True, "is_householder": True, "is_first_home": False, "target_dong": "상도동"})
|
|
b = r.json()
|
|
assert "jeonse" in b and "purchase" in b and "region" in b
|
|
assert b["purchase"]["max_price"] == b["purchase"]["loan_cap"] + 30000
|
|
|
|
def test_safety_check_rent():
|
|
from app import db
|
|
for v in (40000, 42000, 44000):
|
|
db.upsert_market_deal({"house_type": "아파트", "dong_code": "11590", "dong": "신대방동",
|
|
"complex_name": "OO", "area": 42.0, "deal_type": "전세",
|
|
"deposit": v, "sale_amount": None, "deal_ym": "202606", "floor": "5"})
|
|
r = _client().post("/api/realestate/safety-check",
|
|
json={"complex_name": "OO", "area": 42.0, "deal_type": "전세",
|
|
"amount": 28000, "dong_code": "11590"})
|
|
j = r.json()
|
|
assert j["tier"] == "안전" and "disclaimer" in j
|
|
|
|
def test_listings_collect_status():
|
|
assert _client().get("/api/realestate/listings/collect/status").status_code == 200
|
|
|
|
|
|
def test_listings_rematch_endpoint():
|
|
"""MOLIT 재수집 없이 기존 listings+market_deals로 즉시 재판정 — 200 + 요약 카운트."""
|
|
from app import db
|
|
for i, v in enumerate((40000, 42000, 44000)):
|
|
db.upsert_market_deal({"house_type": "아파트", "dong_code": "11590", "dong": "신대방동",
|
|
"complex_name": "OO", "area": 42.0, "deal_type": "전세",
|
|
"deposit": v, "sale_amount": None,
|
|
"deal_ym": f"2026{i+1:02d}", "floor": "5", "source": "molit"})
|
|
db.upsert_listing({"article_no": "RM1", "source": "naver", "deal_type": "전세",
|
|
"deposit": 28000, "area_exclusive": 42.0, "complex_name": "OO",
|
|
"dong": "신대방동", "dong_code": "11590"})
|
|
db.update_listing_criteria({"dongs": ["신대방동"], "deal_types": ["전세"], "max_deposit": 32000,
|
|
"min_area": 40.0, "house_types": ["아파트"]})
|
|
|
|
r = _client().post("/api/realestate/listings/rematch")
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
assert body["total"] == 1
|
|
assert body["passed"] == 1
|
|
assert body["judged"] == 1
|
|
|
|
matches = db.get_listing_matches()
|
|
assert matches[0]["safety_tier"] == "안전"
|