43 lines
1.1 KiB
Python
43 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_equipment():
|
|
# Create a scenario to attach equipment
|
|
resp = client.post(
|
|
"/api/scenarios/", json={"name": "EquipScenario", "description": "equipment scenario"}
|
|
)
|
|
assert resp.status_code == 200
|
|
scenario = resp.json()
|
|
sid = scenario["id"]
|
|
|
|
# Create Equipment item
|
|
eq_payload = {"scenario_id": sid, "name": "Excavator",
|
|
"description": "Heavy machinery"}
|
|
resp2 = client.post("/api/equipment/", json=eq_payload)
|
|
assert resp2.status_code == 200
|
|
eq = resp2.json()
|
|
assert eq["scenario_id"] == sid
|
|
assert eq["name"] == "Excavator"
|
|
|
|
# List Equipment items
|
|
resp3 = client.get("/api/equipment/")
|
|
assert resp3.status_code == 200
|
|
data = resp3.json()
|
|
assert any(item["name"] == "Excavator" and item["scenario_id"]
|
|
== sid for item in data)
|