-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_apps.py
More file actions
77 lines (62 loc) · 2.32 KB
/
test_apps.py
File metadata and controls
77 lines (62 loc) · 2.32 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
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
68
69
70
71
72
73
74
75
76
77
import json
import flask
from apps import app
def test_api_hello():
response = app.test_client().get('/hello')
data = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert data['message'] == 'Hello World'
def test_api_ack_without_param():
response = app.test_client().get('/ack')
assert response.status_code == 404
def test_api_ack_with_interger_param():
response = app.test_client().get('/ack/0')
data = json.loads(response.get_data(as_text=True))
assert response.status_code == 404
assert data['message'] == 'Query Param must be a string'
def test_api_ack_with_string_param():
param = 'test'
response = app.test_client().get(f'/ack/{param}')
data = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert data['message'] == param.upper()
def test_api_postme_without_data():
payload = None
content_type = 'application/json'
response = app.test_client().post(f'/postme',
data=json.dumps(payload),
content_type=content_type
)
data = json.loads(response.get_data(as_text=True))
assert response.status_code == 404
assert data['message'] == 'No Payload'
def test_api_postme_without_required_data():
payload = {'bar': 123}
content_type = 'application/json'
response = app.test_client().post(f'/postme',
data=json.dumps(payload),
content_type=content_type
)
data = json.loads(response.get_data(as_text=True))
assert response.status_code == 404
assert data['message'] == "'foo' key is missing"
def test_api_postme_with_invalid_content_type():
payload = {'foo': 123}
content_type = 'application/text'
response = app.test_client().post(f'/postme',
data=json.dumps(payload),
content_type=content_type
)
data = json.loads(response.get_data(as_text=True))
assert response.status_code == 404
assert data['message'] == 'Invalid Request'
def test_api_postme_with_valid_request():
payload = {'foo': 123}
content_type = 'application/json'
response = app.test_client().post(f'/postme',
data=json.dumps(payload),
content_type=content_type
)
data = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert data['message'] == 'Data parsed successfully'