from __future__ import annotations
import pytest
import respx
from httpx import Response
from frankfurter_forex_mcp.client.frankfurter import FrankfurterClient, FrankfurterClientError
@pytest.mark.asyncio
async def test_latest_returns_payload() -> None:
with respx.mock(base_url="https://api.frankfurter.app") as mock:
mock.get("/latest").respond(
200,
json={"amount": 1.0, "base": "USD", "date": "2026-02-24", "rates": {"BRL": 5.1}},
)
async with FrankfurterClient("https://api.frankfurter.app") as client:
payload = await client.latest(base="USD", targets=["BRL"])
assert payload["base"] == "USD"
assert payload["rates"]["BRL"] == 5.1
@pytest.mark.asyncio
async def test_raises_on_http_error() -> None:
with respx.mock(base_url="https://api.frankfurter.app") as mock:
mock.get("/latest").mock(return_value=Response(500, json={"error": "boom"}))
async with FrankfurterClient("https://api.frankfurter.app") as client:
with pytest.raises(FrankfurterClientError):
await client.latest(base="USD", targets=["BRL"])