"""Tests for the 10-K viewer Flask app.""" import sys from pathlib import Path import pytest sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) import app as viewer # noqa: E402 SAMPLE_SUBS = { "filings": { "recent": { "form": ["10-K", "8-K", "10-Q", "10-K"], "filingDate": ["2024-11-01", "2024-10-15", "2024-08-01", "2023-11-02"], "primaryDocument": [ "aapl-20240928.htm", "aapl-20241015.htm", "aapl-20240628.htm", "aapl-20230930.htm", ], "accessionNumber": [ "0000320193-24-000123", "0000320193-24-000100", "0000320193-24-000090", "0000320193-23-000050", ], } } } @pytest.fixture def client(): viewer._filings_cache.clear() viewer._tickers = None viewer.app.config["TESTING"] = True with viewer.app.test_client() as c: yield c def test_parse_filings_filters_forms(): r = viewer.parse_filings(SAMPLE_SUBS, "0000320193", {"10-K"}) assert len(r) == 2 assert all(f["form"] == "10-K" for f in r) def test_parse_filings_builds_url_and_file(): r = viewer.parse_filings(SAMPLE_SUBS, "0000320193", {"10-K", "10-Q"}) first = r[0] assert first["file"] == "2024-11-01_000032019324000123.html" assert ( first["url"] == "https://www.sec.gov/Archives/edgar/data/0000320193/000032019324000123/aapl-20240928.htm" ) def test_parse_filings_no_matching_forms(): assert viewer.parse_filings(SAMPLE_SUBS, "0000320193", {"20-F"}) == [] def test_clean_ereader_strips_scripts_and_handlers(): html = b"