fix: use ASGITransport for httpx AsyncClient in tests
- httpx.AsyncClient requires ASGITransport for FastAPI app testing - Updated all test files to use correct API
This commit is contained in:
+13
-13
@@ -1,10 +1,10 @@
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
from httpx import AsyncClient, ASGITransport
|
||||
from app.main import app
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_job():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
# Create a source first (job requires source_id)
|
||||
source_resp = await ac.post("/api/sources/", json={
|
||||
"name": "Test Source",
|
||||
@@ -31,7 +31,7 @@ async def test_create_job():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_jobs():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
# Create source and job
|
||||
source_resp = await ac.post("/api/sources/", json={
|
||||
"name": "Test Source",
|
||||
@@ -56,7 +56,7 @@ async def test_list_jobs():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_job():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
source_resp = await ac.post("/api/sources/", json={
|
||||
"name": "Test Source",
|
||||
"type": "local",
|
||||
@@ -80,7 +80,7 @@ async def test_get_job():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_job():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
source_resp = await ac.post("/api/sources/", json={
|
||||
"name": "Test Source",
|
||||
"type": "local",
|
||||
@@ -102,13 +102,13 @@ async def test_delete_job():
|
||||
assert response.status_code == 200
|
||||
|
||||
# Verify deletion
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
get_resp = await ac.get(f"/api/jobs/{job_id}")
|
||||
assert get_resp.status_code == 404
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_job():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
# Create source
|
||||
source_resp = await ac.post("/api/sources/", json={
|
||||
"name": "Test Source",
|
||||
@@ -134,13 +134,13 @@ async def test_run_job():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_job_not_found():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
response = await ac.post("/api/jobs/999/run")
|
||||
assert response.status_code == 404
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_job():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
# Create source
|
||||
source_resp = await ac.post("/api/sources/", json={
|
||||
"name": "Test Source",
|
||||
@@ -169,7 +169,7 @@ async def test_update_job():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_schedule():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
# Create source
|
||||
source_resp = await ac.post("/api/sources/", json={
|
||||
"name": "Test Source",
|
||||
@@ -202,18 +202,18 @@ async def test_create_schedule():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_job_not_found():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
response = await ac.get("/api/jobs/99999")
|
||||
assert response.status_code == 404
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_job_not_found():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
response = await ac.put("/api/jobs/99999", json={"name": "Test"})
|
||||
assert response.status_code == 404
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_job_not_found():
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
|
||||
response = await ac.delete("/api/jobs/99999")
|
||||
assert response.status_code == 404
|
||||
|
||||
Reference in New Issue
Block a user