Esempio n. 1
0
async def test_client_success():
    from opbeat.contrib.asyncio import Client

    client = Client(
        servers=['http://localhost'],
        organization_id='organization_id',
        app_id='app_id',
        secret_token='secret',
        async_mode=False,
        transport_class='.'.join((__name__, MockTransport.__name__)),
    )
    client.send(foo='bar')
    tasks = asyncio.Task.all_tasks()
    task = next(t for t in tasks if t is not asyncio.Task.current_task())
    await task
    assert client.state.status == 1
    transport = client._get_transport(urlparse('http://localhost'))
    assert transport.data == client.encode({'foo': 'bar'})
async def test_client_success():
    from opbeat.contrib.asyncio import Client

    client = Client(
        servers=['http://localhost'],
        organization_id='organization_id',
        app_id='app_id',
        secret_token='secret',
        async_mode=False,
        transport_class='.'.join(
            (__name__, MockTransport.__name__)),
    )
    client.send(foo='bar')
    tasks = asyncio.Task.all_tasks()
    task = next(t for t in tasks if t is not asyncio.Task.current_task())
    await task
    assert client.state.status == 1
    transport = client._get_transport(urlparse('http://localhost'))
    assert transport.data == client.encode({'foo': 'bar'})
Esempio n. 3
0
async def test_client_failure_stdlib_exception(mocker):
    from opbeat.contrib.asyncio import Client
    from opbeat.transport.base import TransportException

    client = Client(
        servers=['http://opbeat'],
        organization_id='organization_id',
        app_id='app_id',
        secret_token='secret',
        async_mode=False,
        transport_class='opbeat.transport.asyncio.AsyncioHTTPTransport',
    )
    mock_client = mocker.Mock()
    mock_client.post = mocker.Mock(side_effect=RuntimeError('oops'))
    transport = client._get_transport(urlparse('http://opbeat'))
    transport.client = mock_client
    client.send(foo='bar')
    tasks = asyncio.Task.all_tasks()
    task = next(t for t in tasks if t is not asyncio.Task.current_task())
    with pytest.raises(TransportException):
        await task
    assert client.state.status == 0
async def test_client_failure_stdlib_exception(mocker):
    from opbeat.contrib.asyncio import Client
    from opbeat.transport.base import TransportException

    client = Client(
        servers=['http://opbeat'],
        organization_id='organization_id',
        app_id='app_id',
        secret_token='secret',
        async_mode=False,
        transport_class='opbeat.transport.asyncio.AsyncioHTTPTransport',
    )
    mock_client = mocker.Mock()
    mock_client.post = mocker.Mock(side_effect=RuntimeError('oops'))
    transport = client._get_transport(urlparse('http://opbeat'))
    transport.client = mock_client
    client.send(foo='bar')
    tasks = asyncio.Task.all_tasks()
    task = next(t for t in tasks if t is not asyncio.Task.current_task())
    with pytest.raises(TransportException):
        await task
    assert client.state.status == 0