-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_headers.py
79 lines (63 loc) · 2.67 KB
/
test_headers.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
"""
.. module:: test_headers
:synopsis: All headers tests are defined here
.. moduleauthor:: Dmitry Berdov <https://github.com/CLearERR>
"""
import requests
import pytest
import allure
import logging
from getparams import get_url
@allure.title("headers")
@allure.suite("1.0.0")
@allure.feature("getheaders")
@pytest.mark.headers
@pytest.mark.positive
@pytest.mark.usefixtures("ini")
@pytest.mark.parametrize("headers_add", [{},
{'Content-Type': 'application/json'},
{'Referer': 'https://httpbin.org/', 'Sec-Fetch-Mode': 'cors'},
{'Accept': ''},
{'User-Agent': '', 'Sec-Fetch-Mode': 'cors'}])
def test_get_headers(headers_add, ini):
"""
**test_get_headers**
This checks different positive scenarios about getting request headers.
Expected result: 200 status-code and correct list of headers.
Available parameters sets:
1) Empty header list
2) 1 Non-default header
3) 2 Non-default headers
4) 1 default header
5) 1 default header and 1 non-default header
Pytest marks: "headers", "positive"
"""
headers_default = {"Accept": "*/*", "Accept-Encoding": "gzip, deflate", "Host": "httpbin.org",
"User-Agent": "python-requests/2.22.0"}
headers_unite = {**headers_default, **headers_add}
logging.info("Headers for addition: {}".format(headers_add))
logging.info("Headers default: {}".format(headers_default))
resp = requests.get(str(get_url(ini) + '/headers'), headers=headers_add)
logging.info("Response: {}".format(resp.text))
assert resp.status_code == 200, "Wrong status code of response."
resp_body = resp.json()['headers']
for key in headers_unite:
assert key in resp_body, "Header key from request doesn't exist in response."
assert str(resp_body[key]) == str(headers_unite[key]), "Wrong value of key in response."
@allure.title("headers")
@allure.suite("1.0.0")
@allure.feature("postheaders")
@pytest.mark.headers
@pytest.mark.negative
@pytest.mark.usefixtures("ini")
@pytest.mark.parametrize("headers_add", [{'Content-Type': 'application/json'}])
def test_post_headers(headers_add, ini):
"""
**test_post_headers**
This checks negative scenario (unsupported operation "POST").
Expected result: 405 status-code
Pytest marks: "headers", "negative"
"""
resp = requests.post(str(get_url(ini) + '/headers'), headers=headers_add)
logging.info("Response: {}".format(resp.text))
assert resp.status_code == 405, "Wrong status code of response."