Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Aug 13, 2024
1 parent d1fe7f2 commit c65afef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion changelog.d/17545.bugfix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Handle lower-case http headers in _Mulitpart_Parser_Protocol.
Handle lower-case http headers in `_Mulitpart_Parser_Protocol`.
24 changes: 13 additions & 11 deletions tests/http/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@


class ReadMultipartResponseTests(TestCase):
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_"
data2 = b"to_stream\r\n--6067d4698f8d40a0a794ea7d7379d53a--\r\n\r\n"
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_"
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_"
multipart_response_data2 = (
b"to_stream\r\n--6067d4698f8d40a0a794ea7d7379d53a--\r\n\r\n"
)
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_"

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"

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

# Start sending data.
protocol.dataReceived(self.data1)
protocol.dataReceived(self.data2)
protocol.dataReceived(self.multipart_response_data1)
protocol.dataReceived(self.multipart_response_data2)
# Close the connection.
protocol.connectionLost(Failure(ResponseDone()))

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

# Start sending data.
protocol.dataReceived(self.data3)
protocol.dataReceived(self.data2)
protocol.dataReceived(self.multipart_response_data_cased)
protocol.dataReceived(self.multipart_response_data2)
# Close the connection.
protocol.connectionLost(Failure(ResponseDone()))

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

# Start sending data.
protocol.dataReceived(self.data1)
protocol.dataReceived(self.multipart_response_data1)

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

# Start sending data.
protocol.dataReceived(self.data1)
protocol.dataReceived(self.multipart_response_data1)
self._assert_error(deferred, protocol)

# More data might have come in.
protocol.dataReceived(self.data2)
protocol.dataReceived(self.multipart_response_data2)

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

# Start sending data.
protocol.dataReceived(self.data1)
protocol.dataReceived(self.multipart_response_data1)
self._assert_error(deferred, protocol)
self._cleanup_error(deferred)

Expand Down

0 comments on commit c65afef

Please sign in to comment.