feat(agent): read-only Firefly III API client

This commit is contained in:
2026-08-23 17:01:16 -05:00
parent 207cdb0ef5
commit efc0ad9451
2 changed files with 98 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
import httpx
import pytest
from agent.firefly import FireflyClient, FireflyError
def make_client(handler) -> FireflyClient:
return FireflyClient(
"http://firefly.test", "tok", transport=httpx.MockTransport(handler)
)
def test_about_sends_bearer_token_and_returns_data():
def handler(request: httpx.Request) -> httpx.Response:
assert request.headers["Authorization"] == "Bearer tok"
assert request.headers["Accept"] == "application/json"
assert request.url.path == "/api/v1/about"
return httpx.Response(200, json={"data": {"version": "6.1.1"}})
assert make_client(handler).about() == {"version": "6.1.1"}
def test_non_200_raises_firefly_error_with_status():
def handler(request: httpx.Request) -> httpx.Response:
return httpx.Response(401, json={"message": "Unauthenticated"})
with pytest.raises(FireflyError, match="401"):
make_client(handler).about()
def test_accounts_walks_all_pages():
def handler(request: httpx.Request) -> httpx.Response:
assert request.url.path == "/api/v1/accounts"
assert request.url.params["type"] == "asset"
page = int(request.url.params.get("page", "1"))
data = {
1: [{"id": "1", "attributes": {"name": "NFCU Checking"}}],
2: [{"id": "2", "attributes": {"name": "Venmo"}}],
}[page]
return httpx.Response(
200,
json={
"data": data,
"meta": {"pagination": {"total_pages": 2, "current_page": page}},
},
)
accounts = make_client(handler).accounts()
assert [a["attributes"]["name"] for a in accounts] == ["NFCU Checking", "Venmo"]