Files
web-page-backend/stock/app/test_holdings_intel.py
2026-05-31 21:37:01 +09:00

18 lines
910 B
Python

from app import holdings_intel as hi
def test_get_holdings_merges_price_and_pnl(monkeypatch):
monkeypatch.setattr(hi.db, "get_all_portfolio", lambda: [
{"id": 1, "broker": "kis", "ticker": "005930", "name": "삼성전자",
"quantity": 10, "avg_price": 70000, "purchase_price": 70000},
{"id": 2, "broker": "kis", "ticker": "AAPL", "name": "Apple",
"quantity": 5, "avg_price": 200, "purchase_price": 200},
])
monkeypatch.setattr(hi.price_fetcher, "get_current_prices",
lambda tickers: {"005930": 77000}) # AAPL 미조회(비KRX)
monkeypatch.setattr(hi, "_krx_tickers", lambda: {"005930"})
hs = hi.get_holdings()
s = {h["ticker"]: h for h in hs}
assert s["005930"]["is_krx"] is True
assert round(s["005930"]["pnl_rate"], 1) == 10.0 # (77000-70000)/70000
assert s["AAPL"]["is_krx"] is False # KRX 외