feat: Implement currency management with models, routes, and UI updates; add backfill script for existing records
This commit is contained in:
54
tests/unit/test_currency_workflow.py
Normal file
54
tests/unit/test_currency_workflow.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from tests.unit.conftest import client
|
||||
|
||||
|
||||
def test_create_capex_with_currency_code_and_list():
|
||||
# create scenario first (reuse helper from other tests)
|
||||
from tests.unit.test_costs import _create_scenario
|
||||
|
||||
sid = _create_scenario()
|
||||
|
||||
# create with currency_code
|
||||
payload = {
|
||||
"scenario_id": sid,
|
||||
"amount": 500.0,
|
||||
"description": "Capex with GBP",
|
||||
"currency_code": "GBP",
|
||||
}
|
||||
resp = client.post("/api/costs/capex", json=payload)
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["currency_code"] == "GBP" or data.get(
|
||||
"currency", {}).get("code") == "GBP"
|
||||
|
||||
|
||||
def test_create_opex_with_currency_id():
|
||||
from tests.unit.test_costs import _create_scenario
|
||||
from routes.currencies import list_currencies
|
||||
|
||||
sid = _create_scenario()
|
||||
|
||||
# fetch currencies to get an id
|
||||
resp = client.get("/api/currencies/")
|
||||
assert resp.status_code == 200
|
||||
currencies = resp.json()
|
||||
assert len(currencies) > 0
|
||||
cid = currencies[0]["id"]
|
||||
|
||||
payload = {
|
||||
"scenario_id": sid,
|
||||
"amount": 120.0,
|
||||
"description": "Opex with explicit id",
|
||||
"currency_id": cid,
|
||||
}
|
||||
resp = client.post("/api/costs/opex", json=payload)
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["currency_id"] == cid
|
||||
|
||||
|
||||
def test_list_currencies_endpoint():
|
||||
resp = client.get("/api/currencies/")
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert isinstance(data, list)
|
||||
assert all("id" in c and "code" in c for c in data)
|
||||
@@ -21,7 +21,7 @@ def _create_scenario(client: TestClient) -> int:
|
||||
|
||||
def test_create_production_record(client: TestClient) -> None:
|
||||
scenario_id = _create_scenario(client)
|
||||
payload = {
|
||||
payload: dict[str, any] = {
|
||||
"scenario_id": scenario_id,
|
||||
"amount": 475.25,
|
||||
"description": "Daily output",
|
||||
|
||||
Reference in New Issue
Block a user