Skip to content

Commit c65afef

Browse files
committed
update tests
1 parent d1fe7f2 commit c65afef

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

changelog.d/17545.bugfix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Handle lower-case http headers in _Mulitpart_Parser_Protocol.
1+
Handle lower-case http headers in `_Mulitpart_Parser_Protocol`.

tests/http/test_client.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@
4949

5050

5151
class ReadMultipartResponseTests(TestCase):
52-
data1 = b"\r\n\r\n--6067d4698f8d40a0a794ea7d7379d53a\r\nContent-Type: application/json\r\n\r\n{}\r\n--6067d4698f8d40a0a794ea7d7379d53a\r\nContent-Type: text/plain\r\nContent-Disposition: inline; filename=test_upload\r\n\r\nfile_"
53-
data2 = b"to_stream\r\n--6067d4698f8d40a0a794ea7d7379d53a--\r\n\r\n"
54-
data3 = b"\r\n\r\n--6067d4698f8d40a0a794ea7d7379d53a\r\ncontent-type: application/json\r\n\r\n{}\r\n--6067d4698f8d40a0a794ea7d7379d53a\r\ncontent-type: text/plain\r\ncontent-disposition: inline; filename=test_upload\r\n\r\nfile_"
52+
multipart_response_data1 = b"\r\n\r\n--6067d4698f8d40a0a794ea7d7379d53a\r\nContent-Type: application/json\r\n\r\n{}\r\n--6067d4698f8d40a0a794ea7d7379d53a\r\nContent-Type: text/plain\r\nContent-Disposition: inline; filename=test_upload\r\n\r\nfile_"
53+
multipart_response_data2 = (
54+
b"to_stream\r\n--6067d4698f8d40a0a794ea7d7379d53a--\r\n\r\n"
55+
)
56+
multipart_response_data_cased = b"\r\n\r\n--6067d4698f8d40a0a794ea7d7379d53a\r\ncOntEnt-type: application/json\r\n\r\n{}\r\n--6067d4698f8d40a0a794ea7d7379d53a\r\nContent-tyPe: text/plain\r\nconTent-dispOsition: inline; filename=test_upload\r\n\r\nfile_"
5557

5658
redirect_data = b"\r\n\r\n--6067d4698f8d40a0a794ea7d7379d53a\r\nContent-Type: application/json\r\n\r\n{}\r\n--6067d4698f8d40a0a794ea7d7379d53a\r\nLocation: https://cdn.example.org/ab/c1/2345.txt\r\n\r\n--6067d4698f8d40a0a794ea7d7379d53a--\r\n\r\n"
5759

@@ -104,8 +106,8 @@ def test_parse_file(self) -> None:
104106
result, deferred, protocol = self._build_multipart_response(249, 250)
105107

106108
# Start sending data.
107-
protocol.dataReceived(self.data1)
108-
protocol.dataReceived(self.data2)
109+
protocol.dataReceived(self.multipart_response_data1)
110+
protocol.dataReceived(self.multipart_response_data2)
109111
# Close the connection.
110112
protocol.connectionLost(Failure(ResponseDone()))
111113

@@ -127,8 +129,8 @@ def test_parse_file_lowercase_headers(self) -> None:
127129
result, deferred, protocol = self._build_multipart_response(249, 250)
128130

129131
# Start sending data.
130-
protocol.dataReceived(self.data3)
131-
protocol.dataReceived(self.data2)
132+
protocol.dataReceived(self.multipart_response_data_cased)
133+
protocol.dataReceived(self.multipart_response_data2)
132134
# Close the connection.
133135
protocol.connectionLost(Failure(ResponseDone()))
134136

@@ -167,7 +169,7 @@ def test_too_large(self) -> None:
167169
result, deferred, protocol = self._build_multipart_response(UNKNOWN_LENGTH, 180)
168170

169171
# Start sending data.
170-
protocol.dataReceived(self.data1)
172+
protocol.dataReceived(self.multipart_response_data1)
171173

172174
self.assertEqual(result.getvalue(), b"file_")
173175
self._assert_error(deferred, protocol)
@@ -178,11 +180,11 @@ def test_additional_data(self) -> None:
178180
result, deferred, protocol = self._build_multipart_response(UNKNOWN_LENGTH, 180)
179181

180182
# Start sending data.
181-
protocol.dataReceived(self.data1)
183+
protocol.dataReceived(self.multipart_response_data1)
182184
self._assert_error(deferred, protocol)
183185

184186
# More data might have come in.
185-
protocol.dataReceived(self.data2)
187+
protocol.dataReceived(self.multipart_response_data2)
186188

187189
self.assertEqual(result.getvalue(), b"file_")
188190
self._assert_error(deferred, protocol)
@@ -196,7 +198,7 @@ def test_content_length(self) -> None:
196198
self.assertFalse(deferred.called)
197199

198200
# Start sending data.
199-
protocol.dataReceived(self.data1)
201+
protocol.dataReceived(self.multipart_response_data1)
200202
self._assert_error(deferred, protocol)
201203
self._cleanup_error(deferred)
202204

0 commit comments

Comments
 (0)