Add models and routes for costs, consumption, equipment, maintenance, and production; implement CRUD operations and unit tests
This commit is contained in:
35
tests/unit/test_production.py
Normal file
35
tests/unit/test_production.py
Normal file
@@ -0,0 +1,35 @@
|
||||
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_production_output():
|
||||
# Create a scenario to attach production output
|
||||
resp = client.post(
|
||||
"/api/scenarios/", json={"name": "ProdScenario", "description": "production scenario"}
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
scenario = resp.json()
|
||||
sid = scenario["id"]
|
||||
|
||||
# Create Production Output item
|
||||
prod_payload = {"scenario_id": sid, "amount": 300.0, "description": "Daily output"}
|
||||
resp2 = client.post("/api/production/", json=prod_payload)
|
||||
assert resp2.status_code == 200
|
||||
prod = resp2.json()
|
||||
assert prod["scenario_id"] == sid
|
||||
assert prod["amount"] == 300.0
|
||||
|
||||
# List Production Output items
|
||||
resp3 = client.get("/api/production/")
|
||||
assert resp3.status_code == 200
|
||||
data = resp3.json()
|
||||
assert any(item["amount"] == 300.0 and item["scenario_id"] == sid for item in data)
|
||||
Reference in New Issue
Block a user