summaryrefslogtreecommitdiff
path: root/backend/tests/test_api.py
diff options
context:
space:
mode:
Diffstat (limited to 'backend/tests/test_api.py')
-rw-r--r--backend/tests/test_api.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py
index 300069c..345c0a3 100644
--- a/backend/tests/test_api.py
+++ b/backend/tests/test_api.py
@@ -1212,6 +1212,49 @@ def test_get_ratios_sector_benchmark_fields(monkeypatch) -> None:
assert result["dividend_yield"]["vs_sector"] == pytest.approx(0.012)
+def test_compute_sector_ratio_benchmarks_without_fmp_key(monkeypatch) -> None:
+ clear_service_caches()
+ monkeypatch.delenv("FMP_API_KEY", raising=False)
+ monkeypatch.setattr(
+ data_service,
+ "get_company_info",
+ lambda symbol: (
+ {"sector": "Technology"}
+ if symbol == "AAPL"
+ else {"sector": "Technology"}
+ if symbol == "MSFT"
+ else {"sector": "Technology"}
+ if symbol == "NVDA"
+ else {"sector": "Healthcare"}
+ ),
+ )
+ monkeypatch.setattr(
+ data_service,
+ "search_tickers",
+ lambda query: [
+ {"symbol": "MSFT", "name": "Microsoft", "exchange": "NASDAQ"},
+ {"symbol": "NVDA", "name": "NVIDIA", "exchange": "NASDAQ"},
+ {"symbol": "UNH", "name": "UnitedHealth", "exchange": "NYSE"},
+ ],
+ )
+ monkeypatch.setattr(
+ data_service,
+ "compute_ttm_ratios",
+ lambda symbol: (
+ {"trailing_pe": 30.0, "current_ratio": 2.0}
+ if symbol == "MSFT"
+ else {"trailing_pe": 20.0, "current_ratio": 1.5}
+ if symbol == "NVDA"
+ else {"trailing_pe": 10.0, "current_ratio": 1.0}
+ ),
+ )
+
+ result = data_service.compute_sector_ratio_benchmarks("AAPL")
+
+ assert result["trailing_pe"] == pytest.approx(25.0)
+ assert result["current_ratio"] == pytest.approx(1.75)
+
+
def test_ticker_ratios_route(monkeypatch) -> None:
"""GET /api/tickers/{symbol}/ratios returns a valid RatiosResponse shape."""
clear_service_caches()