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:
@@ -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_source():
|
||||
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/sources/", json={
|
||||
"name": "Test Source",
|
||||
"type": "local",
|
||||
@@ -18,7 +18,7 @@ async def test_create_source():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_sources():
|
||||
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 first
|
||||
await ac.post("/api/sources/", json={
|
||||
"name": "Test Source",
|
||||
@@ -33,7 +33,7 @@ async def test_list_sources():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_source():
|
||||
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_resp = await ac.post("/api/sources/", json={
|
||||
"name": "Test Source",
|
||||
"type": "local",
|
||||
@@ -47,7 +47,7 @@ async def test_get_source():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_source():
|
||||
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_resp = await ac.post("/api/sources/", json={
|
||||
"name": "Delete Me",
|
||||
"type": "local",
|
||||
@@ -59,13 +59,13 @@ async def test_delete_source():
|
||||
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/sources/{source_id}")
|
||||
assert get_resp.status_code == 404
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_source():
|
||||
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_resp = await ac.post("/api/sources/", json={
|
||||
"name": "Original Name",
|
||||
"type": "local",
|
||||
@@ -82,18 +82,18 @@ async def test_update_source():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_source_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/sources/99999")
|
||||
assert response.status_code == 404
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_source_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/sources/99999", json={"name": "Test"})
|
||||
assert response.status_code == 404
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_source_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/sources/99999")
|
||||
assert response.status_code == 404
|
||||
|
||||
Reference in New Issue
Block a user