From 129a153adb949ebce16c4390826cf55724c3fc33 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Tue, 24 Mar 2020 18:59:22 -0400 Subject: [PATCH] add api_client testing client fixture and basic swagger doc tests --- tests/conftest.py | 18 ++++++++++++++++++ tests/test_routes.py | 2 +- tests/test_swagger.py | 9 +++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/conftest.py create mode 100644 tests/test_swagger.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..b1271106 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,18 @@ +""" +tests.conftest.py + +Global conftest file for shared pytest fixtures +""" +import pytest +from fastapi.testclient import TestClient + + +from app.main import APP + +@pytest.fixture +def api_client(): + """ + Returns a TestClient. + The test client uses the requests library for making http requests. + """ + return TestClient(APP) diff --git a/tests/test_routes.py b/tests/test_routes.py index 5bcf0f69..2006724e 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -32,7 +32,7 @@ def read_file_v1(self, state): return expected_json_output def test_root_api(self, mock_request_get, mock_datetime): - """Validate that / returns content and is not a redirect.""" + """Validate that / returns a 200 and is not a redirect.""" response = self.asgi_client.get("/") assert response.status_code == 200 diff --git a/tests/test_swagger.py b/tests/test_swagger.py new file mode 100644 index 00000000..3d71ae64 --- /dev/null +++ b/tests/test_swagger.py @@ -0,0 +1,9 @@ + +import pytest + +@pytest.mark.parametrize("route",["/", "/docs", "/openapi.json"]) +def test_swagger(api_client, route): + """Test that the swagger ui, redoc and openapi json are available.""" + response = api_client.get(route) + print(f"GET {route} {response}\n\n{response.content}") + assert response.status_code == 200