From 147664128fa0281333ba3150e007ed8e2f6a616a Mon Sep 17 00:00:00 2001 From: Tyler Hoang Date: Mon, 18 May 2026 00:44:58 -0700 Subject: various --- backend/tests/test_api.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'backend') diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index 22df555..b136f23 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -386,3 +386,40 @@ def test_overview_uses_computed_sources_and_ratios(monkeypatch) -> None: assert overview["meta"]["sources"]["ratios.price_to_book"] == "computed" assert overview["meta"]["field_availability"]["ratios.ev_to_ebitda"] is True assert any(signal["key"] == "Valuation" and "24.5x" in signal["value"] for signal in overview["signals"]) + + +def test_financials_route_returns_structure(monkeypatch) -> None: + monkeypatch.setattr( + main.data_service, + "get_financials", + lambda symbol, period="annual": { + "period": "annual", + "income": {"columns": ["FY 2024", "TTM"], "rows": [ + {"label": "Total Revenue", "indent": 0, "is_total": True, + "is_section": False, "is_margin": False, "values": [391_000.0, 394_500.0]}, + ]}, + "balance": {"columns": [], "rows": []}, + "cash_flow": {"columns": [], "rows": []}, + }, + ) + result = main.ticker_financials("AAPL", period="annual") + assert result["period"] == "annual" + assert result["income"]["columns"][0] == "FY 2024" + assert result["income"]["rows"][0]["label"] == "Total Revenue" + + +def test_financials_route_period_param(monkeypatch) -> None: + captured: list[str] = [] + + def mock_get_financials(symbol, period="annual"): + captured.append(period) + return { + "period": period, + "income": {"columns": [], "rows": []}, + "balance": {"columns": [], "rows": []}, + "cash_flow": {"columns": [], "rows": []}, + } + + monkeypatch.setattr(main.data_service, "get_financials", mock_get_financials) + main.ticker_financials("AAPL", period="quarterly") + assert captured == ["quarterly"] -- cgit v1.3-2-g0d8e