-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtest_datastructures_response.py
60 lines (43 loc) · 2.19 KB
/
test_datastructures_response.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pytest
from esmerald import Gateway, get, status
from esmerald.datastructures import JSON
from esmerald.datastructures.encoders import ORJSON, UJSON
from esmerald.testclient import create_client
@pytest.mark.parametrize("response", [JSON, ORJSON, UJSON])
def test_json_datastructure(response, test_client_factory):
@get()
async def home() -> response:
return response(content={"detail": "using JSON structure"})
with create_client(routes=[Gateway(handler=home)]) as client:
response = client.get("/")
assert response.status_code == 200
assert response.json()["detail"] == "using JSON structure"
@pytest.mark.parametrize("response", [JSON, ORJSON, UJSON])
def test_json_datastructure_with_different_status_code(response, test_client_factory):
@get()
async def home_two() -> response:
return response(content={"detail": "using JSON structure"}, status_code=201)
with create_client(routes=[Gateway(handler=home_two)]) as client:
response = client.get("/")
assert response.status_code == 201
assert response.json()["detail"] == "using JSON structure"
@pytest.mark.parametrize("response", [JSON, ORJSON, UJSON])
def test_json_datastructure_with_different_status_code_on_handler(response, test_client_factory):
@get(status_code=status.HTTP_202_ACCEPTED)
async def home_three() -> response:
return response(content={"detail": "using JSON structure"})
with create_client(routes=[Gateway(handler=home_three)]) as client:
response = client.get("/")
assert response.status_code == 202
assert response.json()["detail"] == "using JSON structure"
@pytest.mark.parametrize("response", [JSON, ORJSON, UJSON])
def test_json_datastructure_with_different_status_code_on_handler_two(
response, test_client_factory
):
@get(status_code=status.HTTP_202_ACCEPTED)
async def home_three() -> response:
return response(content={"detail": "using JSON structure"}, status_code=201)
with create_client(routes=[Gateway(handler=home_three)]) as client:
response = client.get("/")
assert response.status_code == 201
assert response.json()["detail"] == "using JSON structure"