from uuid import uuid4 import pytest from models.currency import Currency @pytest.fixture def seeded_currency(db_session): currency = Currency(code="GBP", name="British Pound", symbol="GBP") db_session.add(currency) db_session.commit() db_session.refresh(currency) try: yield currency finally: db_session.delete(currency) db_session.commit() def _create_scenario(api_client): payload = { "name": f"CurrencyScenario-{uuid4()}", "description": "Currency workflow scenario", } resp = api_client.post("/api/scenarios/", json=payload) assert resp.status_code == 200 return resp.json()["id"] def test_create_capex_with_currency_code_and_list(api_client, seeded_currency): sid = _create_scenario(api_client) payload = { "scenario_id": sid, "amount": 500.0, "description": "Capex with GBP", "currency_code": seeded_currency.code, } resp = api_client.post("/api/costs/capex", json=payload) assert resp.status_code == 200 data = resp.json() assert data.get("currency_code") == seeded_currency.code or data.get( "currency", {} ).get("code") == seeded_currency.code def test_create_opex_with_currency_id(api_client, seeded_currency): sid = _create_scenario(api_client) resp = api_client.get("/api/currencies/") assert resp.status_code == 200 currencies = resp.json() assert any(c["id"] == seeded_currency.id for c in currencies) payload = { "scenario_id": sid, "amount": 120.0, "description": "Opex with explicit id", "currency_id": seeded_currency.id, } resp = api_client.post("/api/costs/opex", json=payload) assert resp.status_code == 200 data = resp.json() assert data["currency_id"] == seeded_currency.id def test_list_currencies_endpoint(api_client, seeded_currency): resp = api_client.get("/api/currencies/") assert resp.status_code == 200 data = resp.json() assert isinstance(data, list) assert any(c["id"] == seeded_currency.id for c in data)