Files
stack/tests/prisma/test_congress.py
2026-10-31 20:49:08 -04:00

52 lines
1.2 KiB
Python

"""Congress.gov bill payloads. The transport is injected. No HTTP."""
from __future__ import annotations
import pytest
from prisma.congress import Bill, fetch_bills, parse_bills
_PAYLOAD = {
"bills": [
{
"congress": 119,
"type": "hr",
"number": 1,
"title": "A bill",
"latestAction": {"text": "Introduced"},
}
]
}
_BILL = Bill(
congress=119,
bill_type="hr",
number=1,
title="A bill",
latest_action="Introduced",
)
def test_parse_bills_reads_one_bill():
assert parse_bills(_PAYLOAD) == (_BILL,)
def test_fetch_bills_passes_the_congress_url_to_the_transport():
seen: list[str] = []
def transport(url: str) -> dict[str, object]:
seen.append(url)
return _PAYLOAD
assert fetch_bills(119, key="test-key", transport=transport) == (_BILL,)
assert len(seen) == 1
assert "119" in seen[0]
assert "api_key=test-key" in seen[0]
def test_empty_key_does_not_call_the_transport():
def transport(url: str) -> dict[str, object]:
raise AssertionError(url)
with pytest.raises(ValueError):
fetch_bills(119, key="", transport=transport)