59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from fastapi.testclient import TestClient
|
|
from main import app
|
|
from config.database import Base, engine
|
|
|
|
# Setup and teardown
|
|
|
|
|
|
def setup_module(module):
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
|
|
def teardown_module(module):
|
|
Base.metadata.drop_all(bind=engine)
|
|
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_create_and_list_capex_and_opex():
|
|
# Create a scenario to attach costs
|
|
resp = client.post(
|
|
"/api/scenarios/", json={"name": "CostScenario", "description": "cost scenario"}
|
|
)
|
|
assert resp.status_code == 200
|
|
scenario = resp.json()
|
|
sid = scenario["id"]
|
|
|
|
# Create Capex item
|
|
capex_payload = {"scenario_id": sid,
|
|
"amount": 1000.0, "description": "Initial capex"}
|
|
resp2 = client.post("/api/costs/capex", json=capex_payload)
|
|
assert resp2.status_code == 200
|
|
capex = resp2.json()
|
|
assert capex["scenario_id"] == sid
|
|
assert capex["amount"] == 1000.0
|
|
|
|
# List Capex items
|
|
resp3 = client.get("/api/costs/capex")
|
|
assert resp3.status_code == 200
|
|
data = resp3.json()
|
|
assert any(item["amount"] == 1000.0 and item["scenario_id"]
|
|
== sid for item in data)
|
|
|
|
# Create Opex item
|
|
opex_payload = {"scenario_id": sid, "amount": 500.0,
|
|
"description": "Recurring opex"}
|
|
resp4 = client.post("/api/costs/opex", json=opex_payload)
|
|
assert resp4.status_code == 200
|
|
opex = resp4.json()
|
|
assert opex["scenario_id"] == sid
|
|
assert opex["amount"] == 500.0
|
|
|
|
# List Opex items
|
|
resp5 = client.get("/api/costs/opex")
|
|
assert resp5.status_code == 200
|
|
data_o = resp5.json()
|
|
assert any(item["amount"] == 500.0 and item["scenario_id"]
|
|
== sid for item in data_o)
|