43 lines
996 B
Python
43 lines
996 B
Python
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)
|