Esempio n. 1
0
def test_make_http_exception_unknown():
    mocked_response = mock.Mock(autospec=ClientResponse)
    mocked_response.status = 600
    mocked_response.reason = 'Womp Error'
    exc = make_http_exception(
        AsyncioHTTPResponseAdapter(None)(mocked_response), )
    assert type(exc) == HTTPError
Esempio n. 2
0
def test_response_and_message_and_swagger_result(response_500):
    incoming_response = AsyncioHTTPResponseAdapter(None)(response_500)
    actual = str(
        HTTPError(incoming_response,
                  message="Holy moly!",
                  swagger_result={'msg': 'Kaboom'}))
    assert actual == "500 Server Error: Holy moly!: {'msg': 'Kaboom'}"
def test_asyncio_json(
    mock_wait_for,
    mock_wait_for_result,
    asyncio_response,
    mock_incoming_response,
    event_loop,
):
    response_adapter = AsyncioHTTPResponseAdapter(event_loop)(asyncio_response)

    result = event_loop.run_until_complete(response_adapter.json())
    assert result is mock_wait_for_result
    mock_wait_for.assert_called_once_with(
        mock_incoming_response.json.return_value,
        timeout=asyncio_response.remaining_timeout,
        loop=event_loop,
    )
Esempio n. 4
0
def test_make_http_exception(response_500):
    incoming_response = AsyncioHTTPResponseAdapter(None)(response_500)
    exc = make_http_exception(incoming_response,
                              message="Holy moly!",
                              swagger_result={'msg': 'Kaboom'})
    assert isinstance(exc, HTTPError)
    assert isinstance(exc, HTTPServerError)
    assert type(exc) == HTTPInternalServerError
    assert str(exc) == "500 Server Error: Holy moly!: {'msg': 'Kaboom'}"
Esempio n. 5
0
def test_response_and_message(response_500):
    incoming_response = AsyncioHTTPResponseAdapter(None)(response_500)
    actual = str(HTTPError(incoming_response, message='Kaboom'))
    assert actual == '500 Server Error: Kaboom'
Esempio n. 6
0
def test_response_only(response_500):
    incoming_response = AsyncioHTTPResponseAdapter(None)(response_500)
    assert str(HTTPError(incoming_response)) == '500 Server Error'