@@ -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 \r Accept: 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 \n Accept: 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 \n Accept: 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 \n Accept: 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 \n Cookie: val002\r \n Accept: 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 \n Cookie: val002\r \n Accept: 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