Beispiel #1
0
def test_ChunkedTransferEncodingStreamWriter_write_on_exception_still_closes():
    data = b'BOGUS DATA'
    with mock.patch('girder_worker.docker.io.httplib.HTTPConnection', autospec=True):
        s = ChunkedTransferEncodingStreamWriter('http://bogus.url.com/')
        s.conn.send.side_effect = httplib.HTTPException('Bogus Exception')
        with pytest.raises(httplib.HTTPException):
            s.write(data)
            s.conn.close.assert_called_once()
            assert s._closed is True
Beispiel #2
0
def test_ChunkedTransferEncodingStreamWriter_write_sends_newline_separated_length_and_data():
    data = b'BOGUS DATA'
    with mock.patch('girder_worker.docker.io.httplib.HTTPConnection', autospec=True):
        s = ChunkedTransferEncodingStreamWriter('http://bogus.url.com/')
        s.write(data)
        s.conn.send.assert_has_calls([
            mock.call(hex(len(data))[2:].encode('utf-8')),
            mock.call(b'\r\n'),
            mock.call(data),
            mock.call(b'\r\n')
        ])