From 20b51f706ca772890f9b63d752b946d9ee4c3885 Mon Sep 17 00:00:00 2001 From: gahusb Date: Tue, 28 Apr 2026 08:40:51 +0900 Subject: [PATCH] feat(realestate-profile): expose 5tier districts + min_match_score + notify_enabled Co-Authored-By: Claude Sonnet 4.6 --- realestate-lab/app/models.py | 8 +++-- realestate-lab/tests/test_profile_api.py | 42 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 realestate-lab/tests/test_profile_api.py diff --git a/realestate-lab/app/models.py b/realestate-lab/app/models.py index 686ac00..8c1c460 100644 --- a/realestate-lab/app/models.py +++ b/realestate-lab/app/models.py @@ -1,5 +1,5 @@ -from typing import Optional, List -from pydantic import BaseModel +from typing import Optional, List, Dict +from pydantic import BaseModel, Field class AnnouncementCreate(BaseModel): @@ -80,3 +80,7 @@ class ProfileUpdate(BaseModel): min_area: Optional[float] = None max_area: Optional[float] = None max_price: Optional[int] = None + # 신규 + preferred_districts: Optional[Dict[str, List[str]]] = None + min_match_score: Optional[int] = Field(default=None, ge=0, le=100) + notify_enabled: Optional[bool] = None diff --git a/realestate-lab/tests/test_profile_api.py b/realestate-lab/tests/test_profile_api.py new file mode 100644 index 0000000..807709b --- /dev/null +++ b/realestate-lab/tests/test_profile_api.py @@ -0,0 +1,42 @@ +from fastapi.testclient import TestClient + + +def test_profile_update_accepts_new_fields(): + from app.main import app + body = { + "name": "테스트", + "preferred_districts": { + "S": ["강남구", "서초구"], + "A": ["송파구"], + "B": [], + "C": [], + "D": [], + }, + "min_match_score": 75, + "notify_enabled": True, + } + with TestClient(app) as client: + resp = client.put("/api/realestate/profile", json=body) + assert resp.status_code == 200 + data = resp.json() + assert data["preferred_districts"]["S"] == ["강남구", "서초구"] + assert data["min_match_score"] == 75 + assert data["notify_enabled"] is True + + +def test_profile_get_returns_defaults_for_new_fields(): + from app.main import app + from app.db import upsert_profile, _conn + + # 이전 테스트 데이터 제거 후 새 프로필 삽입 + with _conn() as conn: + conn.execute("DELETE FROM user_profile") + upsert_profile({"name": "기본"}) + + with TestClient(app) as client: + resp = client.get("/api/realestate/profile") + assert resp.status_code == 200 + data = resp.json() + assert data["preferred_districts"] == {} + assert data["min_match_score"] == 70 + assert data["notify_enabled"] is True