MCPcopy
hub / github.com/urllib3/urllib3 / test_send_file_bytes

Method test_send_file_bytes

test/test_http2_connection.py:211–233  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

209 conn._h2_conn._obj.end_stream.assert_called_with(1)
210
211 def test_send_file_bytes(self) -> None:
212 conn = HTTP2Connection("example.com")
213 mock_open = mock.mock_open(read_data=b"foo\r\nbar\r\n")
214 with mock.patch("builtins.open", mock_open):
215 conn.sock = mock.MagicMock(
216 sendall=mock.Mock(return_value=None),
217 )
218 conn._h2_conn._obj.data_to_send = mock.Mock(return_value=b"foo") # type: ignore[method-assign]
219 conn._h2_conn._obj.send_data = mock.Mock(return_value=None) # type: ignore[method-assign]
220 conn._h2_conn._obj.get_next_available_stream_id = mock.Mock(return_value=1) # type: ignore[method-assign]
221 conn._h2_conn._obj.end_stream = mock.Mock(return_value=None) # type: ignore[method-assign]
222
223 body = open("foo", "rb")
224 conn.putrequest("GET", "/")
225 conn.endheaders(message_body=body)
226 conn.send(body)
227
228 conn._h2_conn._obj.data_to_send.assert_called_with()
229 conn.sock.sendall.assert_called_with(b"foo")
230 conn._h2_conn._obj.send_data.assert_called_with(
231 1, b"foo\r\nbar\r\n", end_stream=False
232 )
233 conn._h2_conn._obj.end_stream.assert_called_with(1)
234
235 def test_send_invalid_type(self) -> None:
236 conn = HTTP2Connection("example.com")

Callers

nothing calls this directly

Calls 4

putrequestMethod · 0.95
endheadersMethod · 0.95
sendMethod · 0.95
HTTP2ConnectionClass · 0.90

Tested by

no test coverage detected