def test_region_regulation_toheo_and_normal():
    from app.finance_rules import region_regulation
    assert region_regulation("대치동")["is_toheo"] is True       # 강남 토허
    r = region_regulation("신대방동")
    assert r["is_toheo"] is False and "확인" in r["notes"]

def test_jeonse_budget_equity_plus_loan():
    from app.finance_rules import estimate_jeonse_budget
    b = estimate_jeonse_budget(equity=15000, annual_income=6000)   # 자기자금 1.5억
    assert b["max_deposit"] == b["loan_limit"] + 15000
    assert b["loan_limit"] > 0

def test_purchase_budget_seoul_cap_applies():
    from app.finance_rules import region_regulation, estimate_purchase_budget
    flags = region_regulation("상도동")
    b = estimate_purchase_budget(equity=30000, annual_income=8000,
                                 region_flags=flags, is_first_home=False, is_homeless=True)
    # 수도권 주담대 한도(6·27 대책 6억=60000만원) 캡이 대출가능액에 반영
    assert b["loan_cap"] <= 60000
    assert b["max_price"] == b["loan_cap"] + 30000
    assert 0 < b["ltv_pct"] <= 100
