| 1 |
from typing import AsyncIterator |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from litestar import Litestar, MediaType, get |
| 6 |
from litestar.status_codes import HTTP_200_OK |
| 7 |
from litestar.testing import AsyncTestClient |
| 8 |
|
| 9 |
|
| 10 |
@get(path="/health-check", media_type=MediaType.TEXT, sync_to_thread=False) |
| 11 |
def health_check() -> str: |
| 12 |
return "healthy" |
| 13 |
|
| 14 |
|
| 15 |
app = Litestar(route_handlers=[health_check], debug=True) |
| 16 |
|
| 17 |
|
| 18 |
@pytest.fixture(scope="function") |
| 19 |
async def test_client() -> AsyncIterator[AsyncTestClient[Litestar]]: |
| 20 |
async with AsyncTestClient(app=app) as client: |
| 21 |
yield client |
| 22 |
|
| 23 |
|
| 24 |
async def test_health_check_with_fixture(test_client: AsyncTestClient[Litestar]) -> None: |
| 25 |
response = await test_client.get("/health-check") |
| 26 |
assert response.status_code == HTTP_200_OK |
| 27 |
assert response.text == "healthy" |