Beispiel #1
0
async def test_send_timeout(mock_client):
    from opbeat.transport.asyncio import AsyncioHTTPTransport
    from opbeat.transport.base import TransportException

    transport = AsyncioHTTPTransport(urlparse('http://localhost:9999'))

    mock_client.timeout = 0.1
    transport.client = mock_client

    with pytest.raises(TransportException) as excinfo:
        await transport.send(b'data', {}, timeout=0.0001)
    assert 'Connection to Opbeat server timed out' in str(excinfo.value)
Beispiel #2
0
async def test_send(mock_client):
    from opbeat.transport.asyncio import AsyncioHTTPTransport
    transport = AsyncioHTTPTransport(urlparse('http://localhost:9999'))

    mock_client.status = 202
    mock_client.headers = {'Location': 'http://example.com/foo'}
    transport.client = mock_client

    url = await transport.send(b'data', {'a': 'b'}, timeout=2)
    assert url == 'http://example.com/foo'
    assert mock_client.args == ('http://localhost:9999',)
    assert mock_client.kwargs == {'headers': {'a': 'b'},
                                  'data': b'data'}
Beispiel #3
0
async def test_send_not_found(mock_client):
    from opbeat.transport.asyncio import AsyncioHTTPTransport
    from opbeat.transport.base import TransportException

    transport = AsyncioHTTPTransport(urlparse('http://localhost:9999'))

    mock_client.status = 404
    mock_client.headers = {}
    mock_client.body = b'Not Found'
    transport.client = mock_client

    with pytest.raises(TransportException) as excinfo:
        await transport.send(b'data', {}, timeout=2)
    assert 'Not Found' in str(excinfo.value)
    assert excinfo.value.data == b'data'