Add unit tests for scenarios, parameters, reporting, and simulation features
This commit is contained in:
46
tests/unit/test_parameter.py
Normal file
46
tests/unit/test_parameter.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from models.scenario import Scenario
|
||||
from main import app
|
||||
from config.database import Base, engine
|
||||
from fastapi.testclient import TestClient
|
||||
import pytest
|
||||
import os
|
||||
import sys
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||
|
||||
# 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)
|
||||
|
||||
# Helper to create a scenario
|
||||
|
||||
|
||||
def create_test_scenario():
|
||||
resp = client.post("/api/scenarios/",
|
||||
json={"name": "ParamTest", "description": "Desc"})
|
||||
assert resp.status_code == 200
|
||||
return resp.json()["id"]
|
||||
|
||||
|
||||
def test_create_and_list_parameter():
|
||||
# Ensure scenario exists
|
||||
scen_id = create_test_scenario()
|
||||
# Create a parameter
|
||||
resp = client.post(
|
||||
"/api/parameters/", json={"scenario_id": scen_id, "name": "param1", "value": 3.14})
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["name"] == "param1"
|
||||
# List parameters
|
||||
resp2 = client.get("/api/parameters/")
|
||||
assert resp2.status_code == 200
|
||||
data2 = resp2.json()
|
||||
assert any(p["name"] == "param1" for p in data2)
|
||||
Reference in New Issue
Block a user