42 lines
1.1 KiB
Python
42 lines
1.1 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_maintenance():
|
|
# Create a scenario to attach maintenance
|
|
resp = client.post(
|
|
"/api/scenarios/", json={"name": "MaintScenario", "description": "maintenance scenario"}
|
|
)
|
|
assert resp.status_code == 200
|
|
scenario = resp.json()
|
|
sid = scenario["id"]
|
|
|
|
# Create Maintenance record
|
|
maint_payload = {"scenario_id": sid, "details": "Routine check"}
|
|
resp2 = client.post("/api/maintenance/", json=maint_payload)
|
|
assert resp2.status_code == 200
|
|
maint = resp2.json()
|
|
assert maint["scenario_id"] == sid
|
|
assert maint["details"] == "Routine check"
|
|
|
|
# List Maintenance records
|
|
resp3 = client.get("/api/maintenance/")
|
|
assert resp3.status_code == 200
|
|
data = resp3.json()
|
|
assert any(item["details"] ==
|
|
"Routine check" and item["scenario_id"] == sid for item in data)
|