Skip to content

Commit 9848e39

Browse files
authored
Fixup tests
Signed-off-by: GitHub <[email protected]>
1 parent fc4619b commit 9848e39

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

tests/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Test fixtures for the test suite."""
2+
3+
from collections.abc import Iterator
4+
5+
import pytest
6+
from litestar import Litestar
7+
from litestar.testing import TestClient
8+
9+
from api.server import app
10+
11+
app.debug = True
12+
13+
14+
@pytest.fixture
15+
def test_client() -> Iterator[TestClient[Litestar]]:
16+
"""Create a test client for the Litestar app."""
17+
with TestClient(app=app) as client:
18+
yield client

tests/modules/test_generators.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33
import uuid
44
from http import HTTPStatus
55

6-
from fastapi.testclient import TestClient
6+
from litestar import Litestar
7+
from litestar.testing import TestClient
78

8-
from api.server import app
99

10-
client = TestClient(app)
11-
12-
13-
def test_bulk_uuids() -> None:
10+
def test_bulk_uuids(test_client: TestClient[Litestar]) -> None:
1411
"""Test bulk UUIDs."""
15-
response = client.post("/generators/uuids/", json={"uuid_type": 1, "quantity": 1})
12+
response = test_client.post("/generators/uuids/", json={"uuid_type": 1, "quantity": 1})
1613
assert response.status_code == HTTPStatus.OK
1714
first = response.json()["uuids"][0]
1815
assert isinstance(uuid.UUID(first), uuid.UUID)
1916

2017

21-
def test_random_numbers() -> None:
18+
def test_random_numbers(test_client: TestClient[Litestar]) -> None:
2219
"""Test random numbers."""
23-
response = client.post("/generators/random-numbers/", json={})
20+
response = test_client.post("/generators/random-numbers/", json={})
2421
assert response.status_code == HTTPStatus.OK
2522
assert response.json() == {
2623
"numbers": [1],

tests/test_server.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
from http import HTTPStatus
44

5-
from fastapi.testclient import TestClient
5+
from litestar import Litestar
6+
from litestar.testing import TestClient
67

78
from api import __version__
8-
from api.server import app
99

10-
client = TestClient(app)
1110

12-
13-
def test_read_main() -> None:
11+
def test_get_metadata(test_client: TestClient[Litestar]) -> None:
1412
"""Test getting the root route."""
15-
response = client.get("/")
13+
response = test_client.get("/")
1614
assert response.status_code == HTTPStatus.OK
1715
assert response.json() == {
1816
"version": __version__,

0 commit comments

Comments
 (0)