Remodel/packages/api/tests/test_scenarios.py

47 lines
1.6 KiB
Python

from unittest.mock import AsyncMock, patch
from httpx import AsyncClient
async def test_list_scenarios_empty(client: AsyncClient) -> None:
resp = await client.get("/api/scenarios")
assert resp.status_code == 200
assert resp.json() == []
async def test_create_and_get_scenario(client: AsyncClient) -> None:
mock_pool = AsyncMock()
mock_pool.enqueue_job = AsyncMock()
mock_pool.aclose = AsyncMock()
with patch("remodel_api.routers.scenarios.arq.create_pool", return_value=mock_pool):
resp = await client.post("/api/scenarios", json={"name": "Test Scenario"})
assert resp.status_code == 201
data = resp.json()
assert data["name"] == "Test Scenario"
assert data["status"] == "queued"
scenario_id = data["id"]
resp2 = await client.get(f"/api/scenarios/{scenario_id}")
assert resp2.status_code == 200
assert resp2.json()["id"] == scenario_id
async def test_get_scenario_not_found(client: AsyncClient) -> None:
resp = await client.get("/api/scenarios/nonexistent-id")
assert resp.status_code == 404
async def test_list_scenarios_after_create(client: AsyncClient) -> None:
mock_pool = AsyncMock()
mock_pool.enqueue_job = AsyncMock()
mock_pool.aclose = AsyncMock()
with patch("remodel_api.routers.scenarios.arq.create_pool", return_value=mock_pool):
await client.post("/api/scenarios", json={"name": "S1"})
await client.post("/api/scenarios", json={"name": "S2"})
resp = await client.get("/api/scenarios")
assert resp.status_code == 200
assert len(resp.json()) == 2