예제 #1
0
def test_ChunkedTransferEncodingStreamWriter_close_raises_exceptions_on_bad_http_codes(ec):
    with mock.patch('girder_worker.docker.io.httplib.HTTPConnection', autospec=True):
        s = ChunkedTransferEncodingStreamWriter('http://bogus.url.com/')
        with mock.patch.object(s.conn, 'getresponse', return_value=mock.MagicMock(status=ec)):
            with pytest.raises(Exception):
                s.close()
                s.conn.close.assert_called_once()
예제 #2
0
def test_ChunkedTransferEncodingStreamWriter_close_returns_if_already_closed():
    with mock.patch('girder_worker.docker.io.httplib.HTTPConnection', autospec=True):
        s = ChunkedTransferEncodingStreamWriter('http://bogus.url.com/')
        s._closed = True
        s.close()
        # Nothing was sent
        s.conn.send.assert_not_called()
예제 #3
0
def test_ChunkedTransferEncodingStreamWriter_close_sends_empty_message():
    with mock.patch('girder_worker.docker.io.httplib.HTTPConnection', autospec=True):
        s = ChunkedTransferEncodingStreamWriter('http://bogus.url.com/')
        with mock.patch.object(s.conn, 'getresponse', return_value=mock.MagicMock(status=200)):
            s.close()
            s.conn.send.assert_called_once_with(b'0\r\n\r\n')
            s.conn.close.assert_called_once()
예제 #4
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
예제 #5
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')
        ])
예제 #6
0
    def transform(self, **kwargs):
        from girder_worker.docker.io import (
            ChunkedTransferEncodingStreamWriter)

        return ChunkedTransferEncodingStreamWriter(self.url, self.headers)
예제 #7
0
def test_ChunkedTransferEncodingStreamWriter_custom_headers():
    with mock.patch('girder_worker.docker.io.httplib.HTTPConnection', autospec=True):
        s = ChunkedTransferEncodingStreamWriter('http://bogus.url.com/', headers={
            'Key1': 'Value1',  'Key2': 'Value2'})
        s.conn.putheader.assert_any_call('Key1', 'Value1')
        s.conn.putheader.assert_any_call('Key2', 'Value2')
예제 #8
0
def test_ChunkedTransferEncodingStreamWriter_transfer_encoding_in_headers():
    with mock.patch('girder_worker.docker.io.httplib.HTTPConnection', autospec=True):
        s = ChunkedTransferEncodingStreamWriter('http://bogus.url.com/')
        s.conn.putheader.assert_called_with('Transfer-Encoding', 'chunked')
예제 #9
0
def test_ChunkedTransferEncodingStreamWriter_https_creates_ssl_context():
    with mock.patch('girder_worker.docker.io.httplib.HTTPSConnection', autospec=True):
        with mock.patch('girder_worker.docker.io.ssl') as mock_ssl:
            ChunkedTransferEncodingStreamWriter('https://bogus.url.com/')
            mock_ssl.create_default_context.assert_called_once()