Skip to content

Commit 93a3b56

Browse files
committed
Refactor and improve integration tests suite
1 parent 883c50e commit 93a3b56

File tree

5 files changed

+56
-38
lines changed

5 files changed

+56
-38
lines changed

template/tests/integration/app/__init__.py

Whitespace-only changes.

template/tests/integration/app/controllers/__init__.py

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from {{package_name}}.config import settings
2+
3+
4+
class TestReadyController:
5+
6+
def test_should_return_ok(self, app_runner):
7+
# given
8+
settings.USE_REDIS = False
9+
10+
# when
11+
response = app_runner.get("/api/ready")
12+
13+
# then
14+
assert response.status_code == 200
15+
assert response.json() == {"status": "ok"}
16+
17+
def test_should_return_not_found_when_invalid_uri(self, app_runner):
18+
# given / when
19+
response = app_runner.get("/api/ready/123")
20+
21+
# then
22+
assert response.status_code == 404
23+
{%- if redis %}
24+
25+
def test_should_return_bad_gateway_when_redis_unavailable(self, app_runner):
26+
# given
27+
settings.USE_REDIS = True
28+
29+
# when
30+
response = app_runner.get("/api/ready")
31+
32+
# then
33+
assert response.status_code == 502
34+
assert response.json() == {
35+
"error": {
36+
"code": 502,
37+
"message": "Could not connect to Redis",
38+
"status": "BAD_GATEWAY",
39+
}
40+
}
41+
{% endif %}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
from fastapi.testclient import TestClient
3+
from {{package_name}}.app import get_application
4+
from {{package_name}}.config import settings
5+
6+
7+
@pytest.fixture
8+
def app_runner():
9+
# Overriding to true in order to initialize redis client on FastAPI event
10+
# startup handler. It'll be needed for unit tests.
11+
settings.USE_REDIS = True
12+
app = get_application()
13+
14+
with TestClient(app) as client:
15+
yield client

template/tests/integration/test_ready_endpoint.py.jinja

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)