34 lines
876 B
Python
34 lines
876 B
Python
from fastapi.testclient import TestClient
|
|
from main import app
|
|
from config.database import Base, engine
|
|
from models.distribution import Distribution
|
|
|
|
# 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_distribution():
|
|
# Create distribution
|
|
payload = {"name": "NormalDist", "distribution_type": "normal",
|
|
"parameters": {"mu": 0, "sigma": 1}}
|
|
resp = client.post("/api/distributions/", json=payload)
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["name"] == "NormalDist"
|
|
|
|
# List distributions
|
|
resp2 = client.get("/api/distributions/")
|
|
assert resp2.status_code == 200
|
|
data2 = resp2.json()
|
|
assert any(d["name"] == "NormalDist" for d in data2)
|