"""Bulk fundamentals extracts: listing, Parquet download, ETag / 304.""" from __future__ import annotations import io import pandas as pd import pytest pytestmark = pytest.mark.usefixtures("fundamentals_data") def test_bulk_list_and_download_with_etag(client): r = client.get("/v1/bulk/fundamentals") assert r.status_code == 200 years = [y["year"] for y in r.json()["data"]] assert 2024 in years r = client.get("/v1/bulk/fundamentals/2024.parquet") assert r.status_code == 200 and r.headers["content-type"] == "application/vnd.apache.parquet" etag = r.headers["ETag"] assert etag.startswith('"') and int(r.headers["X-Row-Count"]) > 0 df = pd.read_parquet(io.BytesIO(r.content)) assert set(df["ticker"]) == {"AAPL", "MSFT", "SHAK"} and set(df["fiscal_year"]) == {2024} assert {"income", "balance", "cashflow"} == set(df["statement"]) aapl_q2 = df[(df.ticker == "AAPL") & (df.statement == "income") & (df.fiscal_quarter == 2)] assert len(aapl_q2) == 1 and float(aapl_q2["revenue"].iloc[0]) == 90_753_000_000 # latest version only: one row per (company, statement, period) assert not df.duplicated(["cik", "statement", "fiscal_year", "fiscal_quarter"]).any() r304 = client.get("/v1/bulk/fundamentals/2024.parquet", headers={"If-None-Match": etag}) assert r304.status_code == 304 and r304.headers["X-Row-Count"] == "0" and r304.headers["ETag"] == etag r = client.get("/v1/bulk/fundamentals/2024.parquet", headers={"If-None-Match": '"stale"'}) assert r.status_code == 200 listed = next(y for y in client.get("/v1/bulk/fundamentals").json()["data"] if y["year"] == 2024) assert listed["etag"] == etag and listed["stale"] is False def test_bulk_errors(client): r = client.get("/v1/bulk/fundamentals/1999.parquet") assert r.status_code == 400 and r.json()["error"]["code"] == "INVALID_PARAMETER" r = client.get("/v1/bulk/fundamentals/2099.parquet") assert r.status_code == 404 and r.json()["error"]["code"] == "NOT_FOUND" and "available_years" in r.json()["error"]["details"]