Add unit tests for scenarios, parameters, reporting, and simulation features
This commit is contained in:
42
tests/unit/test_simulation.py
Normal file
42
tests/unit/test_simulation.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from services.simulation import run_simulation
|
||||
from main import app
|
||||
from config.database import Base, engine
|
||||
from fastapi.testclient import TestClient
|
||||
import pytest
|
||||
|
||||
# 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)
|
||||
|
||||
# Direct function test
|
||||
|
||||
|
||||
def test_run_simulation_function_returns_list():
|
||||
results = run_simulation([], iterations=10)
|
||||
assert isinstance(results, list)
|
||||
assert results == []
|
||||
|
||||
# Endpoint tests
|
||||
|
||||
|
||||
def test_simulation_endpoint_no_params():
|
||||
resp = client.post("/api/simulations/run", json=[])
|
||||
assert resp.status_code == 400
|
||||
assert resp.json()["detail"] == "No parameters provided"
|
||||
|
||||
|
||||
def test_simulation_endpoint_success():
|
||||
params = [{"name": "param1", "value": 2.5}]
|
||||
resp = client.post("/api/simulations/run", json=params)
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert isinstance(data, list)
|
||||
Reference in New Issue
Block a user