This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
67 lines (57 loc) · 2.24 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
""" Sanic camelcase middleware tests module
"""
import json
from humps import camelize
from main import app as main_app
from main_options import app as main_options_app
def test_get_request():
"""test_get_request function tests get requests for middleware
The purpose of this test is to check if the middleware
would work if the request has no payload in case of
"GET" requests. However the respons should be camilized.
"""
request, response = main_app.test_client.get("/")
assert response.status == 200
assert response.json == {"isCamelcase": True, "message": "Hello_world"}
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 = {"my_value": "test_value"}
request, response = main_app.test_client.post(
"/post", data=json.dumps(data)
)
assert response.status == 200
assert response.json == {"isCamelcase": True, "message": camelize(data)}
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 = {"myValue": "test_value"}
request, response = main_app.test_client.post(
"/post", data=json.dumps(data)
)
assert response.status == 200
assert response.json == {"isCamelcase": True, "message": camelize(data)}
def test_request_post_body_without_response_body():
"""test_request_post_body_without_response_body function
checks the case where reponse does not contain a body
"""
data = {"my_value": "test_value"}
request, response = main_app.test_client.put(
"/empty", data=json.dumps(data)
)
assert response.status == 204
def test_request_post_body_not_camelcased():
"""test_request_post_body_camelcased function tests post request
with `camelize_response=False`.
"""
data = {"my_value": "test_value"}
request, response = main_options_app.test_client.post(
"/post", data=json.dumps(data)
)
assert response.status == 200
assert response.json == {"is_camelcase": False, "message": data}