-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.py
More file actions
29 lines (23 loc) · 1.14 KB
/
Copy pathtest_main.py
File metadata and controls
29 lines (23 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pytest
from fastapi.testclient import TestClient
from main import MyApp, AppConfig
config = AppConfig.parse_file( "config/config.yaml")
class TestConstructPayload:
# note we test the function not the endpoint
def test_happy(self):
assert MyApp.construct_payload("test", 1, None) == "endpoint called with payload: test 1"
class TestEndpoint:
def test_endpoint(self):
my_app = MyApp(config)
test_app = my_app.build_app()
with TestClient(test_app) as client:
response = client.post("/endpoint", json={"string": "test", "integer": 10})
assert response.status_code == 200
assert response.json() == {"message": "endpoint called with payload: test 10"}
def test_endpoint_w_optional_param(self):
my_app = MyApp(config)
test_app = my_app.build_app()
with TestClient(test_app) as client:
response = client.post("/endpoint", json={"string": "test", "integer": 10, "optional_param": "optional"})
assert response.status_code == 200
assert response.json() == {"message": "endpoint called with payload: test 10, optional"}