Files
calminer/tests/unit/test_currency_workflow.py
zwitschi 97b1c0360b
Some checks failed
Run Tests / e2e tests (push) Failing after 1m27s
Run Tests / lint tests (push) Failing after 6s
Run Tests / unit tests (push) Failing after 7s
Refactor test cases for improved readability and consistency
- Updated test functions in various test files to enhance code clarity by formatting long lines and improving indentation.
- Adjusted assertions to use multi-line formatting for better readability.
- Added new test cases for theme settings API to ensure proper functionality.
- Ensured consistent use of line breaks and spacing across test files for uniformity.
2025-10-27 10:32:55 +01:00

76 lines
2.1 KiB
Python

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)