def test_nova_responder_cannot_str_exc(mock_publish): config = {AMQP_URI_CONFIG_KEY: ''} responder = NovaResponder(config, "msgid") class BadException(Exception): def __str__(self): raise Exception('boom') # un-str-able exception exc = BadException() result, exc_info = responder.send_response( 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 }
def test_nova_responder(mock_publish): config = {AMQP_URI_CONFIG_KEY: ''} responder = NovaResponder(config, "msgid") # serialisable result result, exc_info = responder.send_response(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 }
def test_nova_responder_unserializale_result(mock_publish): config = {AMQP_URI_CONFIG_KEY: ''} responder = NovaResponder(config, "msgid") # unserialisable result obj = object() result, exc_info = responder.send_response(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 }