55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
from tests.unit.test_costs 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)
|