File tree Expand file tree Collapse file tree 3 files changed +28
-15
lines changed
Expand file tree Collapse file tree 3 files changed +28
-15
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 33import uuid
44from 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 ],
Original file line number Diff line number Diff line change 22
33from http import HTTPStatus
44
5- from fastapi .testclient import TestClient
5+ from litestar import Litestar
6+ from litestar .testing import TestClient
67
78from 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__ ,
You can’t perform that action at this time.
0 commit comments