37 lines
956 B
Python
37 lines
956 B
Python
# ensure project root is on sys.path for module imports
|
|
from main import app
|
|
from routes.scenarios import router
|
|
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__))))
|
|
|
|
# Create tables for testing
|
|
|
|
|
|
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_scenario():
|
|
# Create a scenario
|
|
response = client.post(
|
|
"/api/scenarios/", json={"name": "Test", "description": "Desc"})
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["name"] == "Test"
|
|
# List scenarios
|
|
response2 = client.get("/api/scenarios/")
|
|
assert response2.status_code == 200
|
|
data2 = response2.json()
|
|
assert any(s["name"] == "Test" for s in data2)
|