1
1
import pytest
2
2
from fastapi.testclient import TestClient
3
- from {{package_name}}.app.asgi import get_app
3
+ from {{package_name}}.app import get_application
4
4
5
5
6
- @pytest.fixture
7
- def client():
8
- # This is an example fixture for generated test sake.
9
- # By default there should be a 'app' fixture just like this under:
10
- # tests/unit/app/conftest.py
11
- app = get_app()
12
- with TestClient(app) as client:
13
- yield client
14
- {% - for endpoint , method in endpoints .items () %}
6
+ class Test{{ controller_name.capitalize() }}Controller:
15
7
8
+ @pytest.fixture
9
+ def client(self):
10
+ # This is an example fixture for generated test sake.
11
+ # By default there should be a 'app_runner' fixture just like this under:
12
+ # tests/unit/app/conftest.py
13
+ app = get_application()
14
+ with TestClient(app) as client:
15
+ yield client
16
+ {% for endpoint , method in endpoints .items () %}
17
+ def test_should{{ endpoint.lower().replace('-','_') }}_return_ok(self, client):
18
+ # given / when
19
+ response = client.{{ method.lower() }}("/api/{{ controller_name }}/{{ endpoint.lower().replace('-','_') }}")
16
20
17
- def test_{{ endpoint.lower().replace('-','_') }}(client):
18
- response = client.{{ method.lower() }}("/{{ controller_name }}/{{ endpoint.lower().replace('-','_') }}")
19
- assert response.status_code == 200
20
- assert response.json() == {"hello": "world"}
21
-
22
-
23
- {% - endfor %}
24
- {% - raw %}
25
-
26
- {% endraw %}
21
+ # then
22
+ assert response.status_code == 200
23
+ assert response.json() == {"hello": "world"}
24
+ {% endfor %}
0 commit comments