-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_popup_api.py
80 lines (61 loc) · 3.99 KB
/
test_popup_api.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
68
69
70
71
72
73
74
75
76
77
78
79
80
import pytest
import requests
# Methods that are used in API tests:
def _make_post_receive_response(url_port_endp, user_action, feedback):
return requests.post(url_port_endp, json={"user_action": user_action, "feedback": feedback})
# API Tests:
@pytest.mark.parametrize("user_action, feedback",
[("0", 'Testing API valid "0" user action ~!@#$%^&*()_+{}|:<>?,./;\'[]\\|=-`'),
("1", 'Testing API valid "1" user action'),
("2", 'Testing API valid "2" user action'),
("3", 'Testing API valid "3" user action'),
("4", 'Testing API valid "4" user action'),
("5", 'Testing API valid "5" user action'),
("6", 'Testing API valid "6" user action'),
("7", ""),
("8", ""),
("9", ""),
("10", "")])
def test_valid_user_action(url_port_endp, user_action, feedback):
resp = _make_post_receive_response(url_port_endp[0], user_action, feedback)
assert resp.status_code == 200
@pytest.mark.parametrize("user_action, feedback", [("-1", 'Testing API inval "-1" user action'),
("11", 'Testing API inval "11" user action')])
def test_inval_user_action(url_port_endp, user_action, feedback):
resp = _make_post_receive_response(url_port_endp[0], user_action, feedback)
assert resp.status_code == 400
@pytest.mark.parametrize("user_action, feedback", [("", "Testing API empty user action")])
def test_inval_empty_user_action(url_port_endp, user_action, feedback):
resp = _make_post_receive_response(url_port_endp[0], user_action, feedback)
assert resp.status_code == 400
@pytest.mark.parametrize("user_action, feedback", [("5", "Testing API inval endpoint")])
def test_inval_endp(url_port_endp, user_action, feedback):
resp = _make_post_receive_response(url_port_endp[1], user_action, feedback)
assert resp.status_code == 404
@pytest.mark.parametrize("user_action, feedback", [("5", "Testing API empty endpoint")])
def test_inval_empty_endp(url_port_endp, user_action, feedback):
resp = _make_post_receive_response(url_port_endp[2], user_action, feedback)
assert resp.status_code == 404
@pytest.mark.parametrize("user_action, feedback", [("5", "Testing API too long feedback Testing too long feedback \
Testing too long feedback Testing too long feedback Testing too long feedback Testing too long feedback \
Testing too long feedback Testing too long feedback Testing too long feedback Testing too long feedback")])
def test_inval_too_long_feedback(url_port_endp, user_action, feedback):
resp = _make_post_receive_response(url_port_endp[0], user_action, feedback)
assert resp.status_code == 400
@pytest.mark.parametrize("user_action, feedback", [("7", "Testing API non empty feedback user action greater than 6")])
def test_inval_non_empty_feedback_user_action_gt_6(url_port_endp, user_action, feedback):
resp = _make_post_receive_response(url_port_endp[0], user_action, feedback)
assert resp.status_code == 400
@pytest.mark.parametrize("user_action, feedback", [("5", "Testing API not JSON request")])
def test_inval_not_json_request(url_port_endp, user_action, feedback):
xml = """<?xml version='1.0' encoding='utf-8'?>
<a>01</a>"""
headers = {'Content-Type': 'application/xml'}
resp = requests.post(url_port_endp[0], data=xml, headers=headers)
assert resp.status_code == 400
# @pytest.mark.parametrize("user_action, feedback", [("5", "Testing API invalid method")])
# def test_inval_method(url_port_endp, user_action, feedback):
# resp = requests.get(url_port_endp[0], json={"user_action": user_action, "feedback": feedback})
# resp = requests.put(url_port_endp[0], json={"user_action": user_action, "feedback": feedback})
# resp = requests.delete(url_port_endp[0], json={"user_action": user_action, "feedback": feedback})
# assert resp.status_code == 400