Skip to content

Commit 60ef74f

Browse files
committed
Add more tests for w3lib.http
1 parent 3bc99d6 commit 60ef74f

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/test_http.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def test_basic_auth_header(self):
1414
self.assertEqual(b'Basic c29tZXVzZXI6QDx5dTk-Jm8_UQ==',
1515
basic_auth_header('someuser', '@<yu9>&o?Q'))
1616

17+
def test_headers_raw_dict_none(self):
18+
self.assertIsNone(headers_raw_to_dict(None))
19+
self.assertIsNone(headers_dict_to_raw(None))
20+
1721
def test_headers_raw_to_dict(self):
1822
raw = b"Content-type: text/html\n\rAccept: gzip\n\n"
1923
dct = {b'Content-type': [b'text/html'], b'Accept': [b'gzip']}
@@ -29,3 +33,57 @@ def test_headers_dict_to_raw(self):
2933
b'Content-type: text/html\r\nAccept: gzip'
3034
)
3135

36+
def test_headers_dict_to_raw_listtuple(self):
37+
dct = OrderedDict([
38+
(b'Content-type', [b'text/html']),
39+
(b'Accept', [b'gzip'])
40+
])
41+
self.assertEqual(
42+
headers_dict_to_raw(dct),
43+
b'Content-type: text/html\r\nAccept: gzip'
44+
)
45+
46+
dct = OrderedDict([
47+
(b'Content-type', (b'text/html',)),
48+
(b'Accept', (b'gzip',))
49+
])
50+
self.assertEqual(
51+
headers_dict_to_raw(dct),
52+
b'Content-type: text/html\r\nAccept: gzip'
53+
)
54+
55+
dct = OrderedDict([
56+
(b'Cookie', (b'val001', b'val002')),
57+
(b'Accept', b'gzip')
58+
])
59+
self.assertEqual(
60+
headers_dict_to_raw(dct),
61+
b'Cookie: val001\r\nCookie: val002\r\nAccept: gzip'
62+
)
63+
64+
dct = OrderedDict([
65+
(b'Cookie', [b'val001', b'val002']),
66+
(b'Accept', b'gzip')
67+
])
68+
self.assertEqual(
69+
headers_dict_to_raw(dct),
70+
b'Cookie: val001\r\nCookie: val002\r\nAccept: gzip'
71+
)
72+
73+
def test_headers_dict_to_raw_wrong_values(self):
74+
dct = OrderedDict([
75+
(b'Content-type', 0),
76+
])
77+
self.assertEqual(
78+
headers_dict_to_raw(dct),
79+
b''
80+
)
81+
82+
dct = OrderedDict([
83+
(b'Content-type', 1),
84+
(b'Accept', [b'gzip'])
85+
])
86+
self.assertEqual(
87+
headers_dict_to_raw(dct),
88+
b'Accept: gzip'
89+
)

0 commit comments

Comments
 (0)