-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests.py
52 lines (45 loc) · 1.59 KB
/
tests.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
# -*- coding: utf-8 -*-
""" Sanic camelcase middleware tests module
"""
import json
from humps import camelize
from main import app
from starlette.testclient import TestClient
client = TestClient(app)
def test_get_request():
"""test_get_request function tests get requests for middleware
The purpose of this test is to check if the module would work if the request
has no payload in case of "GET" requests.
However the respons should be camilized.
"""
response = client.get("/user/get")
assert response.status_code == 200
assert response.json() == {
"firstName": "John",
"lastName": "Doe",
"age": 30,
}
def test_request_post_body_snakecased():
"""test_request_post_body_snakecased function tests post request with snake_cased keys.
The expected return should be camelCased response body
"""
data = {"first_name": "Ahmed", "last_name": "Okasha", "age": 30}
response = client.post("/user/create", json=data)
assert response.status_code == 200
assert response.json() == {
"firstName": "Ahmed",
"lastName": "Okasha",
"age": 30,
}
def test_request_post_body_camelcased():
"""test_request_post_body_camelcased function tests post request with camelCased keys.
The expected return should be camelCased response body as well
"""
data = {"firstName": "Ahmed", "lastName": "Okasha", "age": 30}
response = client.post("/user/create", json=data)
assert response.status_code == 200
assert response.json() == {
"firstName": "Ahmed",
"lastName": "Okasha",
"age": 30,
}