Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make test use fixture #997

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions ibis-server/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
from fastapi.testclient import TestClient
import pytest

from app.main import app
pytestmark = pytest.mark.anyio

client = TestClient(app)

@pytest.fixture(scope="session")
def anyio_backend():
return "asyncio"

def test_root():
response = client.get("/")
assert response.status_code == 200
assert response.url == client.base_url.join("/docs")

async def test_root(client):
response = await client.get("/")
assert response.status_code == 307
assert response.next_request.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",
Expand All @@ -27,16 +30,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
Loading