From 6505d5116f68a1f7e3b04e9689070b27aee36dda Mon Sep 17 00:00:00 2001 From: Grieve Date: Thu, 19 Dec 2024 17:02:59 +0800 Subject: [PATCH 1/3] test: make test use fixture --- ibis-server/tests/test_main.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/ibis-server/tests/test_main.py b/ibis-server/tests/test_main.py index 09e4a2cbc..1e862120b 100644 --- a/ibis-server/tests/test_main.py +++ b/ibis-server/tests/test_main.py @@ -1,24 +1,17 @@ -from fastapi.testclient import TestClient - -from app.main import app - -client = TestClient(app) - - -def test_root(): - response = client.get("/") +async def test_root(client): + response = await client.get("/") assert response.status_code == 200 assert response.url == client.base_url.join("/docs") -def test_health(): - response = client.get("/health") +async def test_health(client): + response = await client.get("/health") assert response.status_code == 200 assert response.json() == {"status": "ok"} -def test_config(): - response = client.get("/config") +async def test_config(client): + response = await client.get("/config") assert response.status_code == 200 assert response.json() == { "wren_engine_endpoint": "http://localhost:8080", @@ -27,16 +20,16 @@ def test_config(): } -def test_update_diagnose(): - response = client.patch("/config", json={"diagnose": True}) +async def test_update_diagnose(client): + response = await client.patch("/config", json={"diagnose": True}) assert response.status_code == 200 assert response.json()["diagnose"] is True - response = client.get("/config") + response = await client.get("/config") assert response.status_code == 200 assert response.json()["diagnose"] is True - response = client.patch("/config", json={"diagnose": False}) + response = await client.patch("/config", json={"diagnose": False}) assert response.status_code == 200 assert response.json()["diagnose"] is False - response = client.get("/config") + response = await client.get("/config") assert response.status_code == 200 assert response.json()["diagnose"] is False From 7936735c74e1189556afe4699a38efe50ed90782 Mon Sep 17 00:00:00 2001 From: Grieve Date: Thu, 19 Dec 2024 17:33:45 +0800 Subject: [PATCH 2/3] fix: add marker and backend --- ibis-server/tests/test_main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ibis-server/tests/test_main.py b/ibis-server/tests/test_main.py index 1e862120b..e47a09d47 100644 --- a/ibis-server/tests/test_main.py +++ b/ibis-server/tests/test_main.py @@ -1,3 +1,13 @@ +import pytest + +pytestmark = pytest.mark.anyio + + +@pytest.fixture(scope="session") +def anyio_backend(): + return "asyncio" + + async def test_root(client): response = await client.get("/") assert response.status_code == 200 From d708221919c4dcb2fde950612f100179c2a4a656 Mon Sep 17 00:00:00 2001 From: Grieve Date: Thu, 19 Dec 2024 17:44:30 +0800 Subject: [PATCH 3/3] fix: assert actual --- ibis-server/tests/test_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ibis-server/tests/test_main.py b/ibis-server/tests/test_main.py index e47a09d47..b7f3207c0 100644 --- a/ibis-server/tests/test_main.py +++ b/ibis-server/tests/test_main.py @@ -10,8 +10,8 @@ def anyio_backend(): async def test_root(client): response = await client.get("/") - assert response.status_code == 200 - assert response.url == client.base_url.join("/docs") + assert response.status_code == 307 + assert response.next_request.url == client.base_url.join("/docs") async def test_health(client):