Skip to content

Commit dc943b1

Browse files
committed
add api_client testing client fixture and basic swagger doc tests
1 parent 5202876 commit dc943b1

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

tests/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
tests.conftest.py
3+
4+
Global conftest file for shared pytest fixtures
5+
"""
6+
import pytest
7+
from fastapi.testclient import TestClient
8+
9+
10+
from app.main import APP
11+
12+
@pytest.fixture
13+
def api_client():
14+
"""
15+
Returns a TestClient.
16+
The test client uses the requests library for making http requests.
17+
"""
18+
return TestClient(APP)

tests/test_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def read_file_v1(self, state):
3232
return expected_json_output
3333

3434
def test_root_api(self, mock_request_get, mock_datetime):
35-
"""Validate that / returns content and is not a redirect."""
35+
"""Validate that / returns a 200 and is not a redirect."""
3636
response = self.asgi_client.get("/")
3737

3838
assert response.status_code == 200

tests/test_swagger.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
import pytest
3+
4+
@pytest.mark.parametrize("route",["/", "/docs", "/openapi.json"])
5+
def test_swagger(api_client, route):
6+
"""Test that the swagger ui, redoc and openapi json are available."""
7+
response = api_client.get(route)
8+
print(f"GET {route} {response}\n\n{response.content}")
9+
assert response.status_code == 200

0 commit comments

Comments
 (0)