Esempio n. 1
0
def test_nova_responder(mock_publish):

    container = Mock()
    container.config = {AMQP_URI_CONFIG_KEY: ''}

    responder = NovaResponder("msgid")

    # serialisable result
    result, exc_info = responder.send_response(container, True, None)
    assert result is True
    assert exc_info is None

    assert mock_publish.call_count == 2
    data_call, marker_call = mock_publish.call_args_list
    (data_msg,), _ = data_call
    (marker_msg,), _ = marker_call

    assert data_msg == {
        'failure': None,
        'result': True,
        'ending': False
    }
    assert marker_msg == {
        'failure': None,
        'result': None,
        'ending': True
    }
Esempio n. 2
0
def test_nova_responder_cannot_str_exc(mock_publish):

    container = Mock()
    container.config = {AMQP_URI_CONFIG_KEY: ''}

    responder = NovaResponder("msgid")

    class BadException(Exception):
        def __str__(self):
            raise Exception('boom')

    # un-str-able exception
    exc = BadException()
    result, exc_info = responder.send_response(
        container, True, (BadException, exc, "tb"))
    assert result is True
    assert exc_info == (BadException, exc, "tb")

    assert mock_publish.call_count == 2
    data_call, _ = mock_publish.call_args_list
    (data_msg,), _ = data_call

    assert data_msg == {
        'failure': ('BadException', "[__str__ failed]"),
        'result': True,
        'ending': False
    }
Esempio n. 3
0
def test_nova_responder_cannot_str_exc(mock_publish):

    container = Mock()
    container.config = {AMQP_URI_CONFIG_KEY: ''}

    responder = NovaResponder("msgid")

    class BadException(Exception):
        def __str__(self):
            raise Exception('boom')

    # un-str-able exception
    exc = BadException()
    result, exc_info = responder.send_response(container, True,
                                               (BadException, exc, "tb"))
    assert result is True
    assert exc_info == (BadException, exc, "tb")

    assert mock_publish.call_count == 2
    data_call, _ = mock_publish.call_args_list
    (data_msg, ), _ = data_call

    assert data_msg == {
        'failure': ('BadException', "[__str__ failed]"),
        'result': True,
        'ending': False
    }
Esempio n. 4
0
def test_nova_responder(mock_publish):

    container = Mock()
    container.config = {AMQP_URI_CONFIG_KEY: ''}

    responder = NovaResponder("msgid")

    # serialisable result
    result, exc_info = responder.send_response(container, True, None)
    assert result is True
    assert exc_info is None

    assert mock_publish.call_count == 2
    data_call, marker_call = mock_publish.call_args_list
    (data_msg, ), _ = data_call
    (marker_msg, ), _ = marker_call

    assert data_msg == {'failure': None, 'result': True, 'ending': False}
    assert marker_msg == {'failure': None, 'result': None, 'ending': True}
Esempio n. 5
0
def test_nova_responder_unserializale_result(mock_publish):

    container = Mock()
    container.config = {AMQP_URI_CONFIG_KEY: ''}

    responder = NovaResponder("msgid")

    # unserialisable result
    obj = object()
    result, exc_info = responder.send_response(container, obj, None)
    assert result is None
    assert exc_info == (TypeError, ANY, ANY)

    assert mock_publish.call_count == 2
    data_call, _ = mock_publish.call_args_list
    (data_msg,), _ = data_call

    assert data_msg == {
        'failure': ('TypeError', "{} is not JSON serializable".format(obj)),
        'result': None,
        'ending': False
    }
Esempio n. 6
0
def test_nova_responder_unserializale_result(mock_publish):

    container = Mock()
    container.config = {AMQP_URI_CONFIG_KEY: ''}

    responder = NovaResponder("msgid")

    # unserialisable result
    obj = object()
    result, exc_info = responder.send_response(container, obj, None)
    assert result is None
    assert exc_info == (TypeError, ANY, ANY)

    assert mock_publish.call_count == 2
    data_call, _ = mock_publish.call_args_list
    (data_msg, ), _ = data_call

    assert data_msg == {
        'failure': ('TypeError', "{} is not JSON serializable".format(obj)),
        'result': None,
        'ending': False
    }