def test_response_failure_initialization_with_exception(response_type): response = ResponseFailure(response_type, Exception('Just an exception message')) assert bool(response) is False assert response.type == response_type assert response.message == 'Exception: Just an exception message'
def test_response_failure_contains_value(response_type, response_message): response = ResponseFailure(response_type, response_message) assert response.value == { 'type': response_type, 'message': response_message }
def test_response_failure_from_invalid_request_object_with_errors(): request_object = InvalidRequestObject() request_object.add_error('path', 'Is mandatory') request_object.add_error('path', "can't be blank") response = ResponseFailure.build_from_invalid_request_object( request_object) assert bool(response) is False assert response.type == 400 assert response.message == "path: Is mandatory\npath: can't be blank"
def test_response_failure_build_system_error(): response = ResponseFailure.build_system_error(message="test message") assert bool(response) is False assert response.type == 500 assert response.message == "test message"
def test_response_failure_build_parameters_error(): response = ResponseFailure.build_parameters_error(message="test message") assert bool(response) is False assert response.type == 400 assert response.message == "test message"
def test_response_failure_build_resource_error(): response = ResponseFailure.build_resource_error(message="test message") assert bool(response) is False assert response.type == 404 assert response.message == "test message"
def test_response_failure_from_invalid_request_object(): response = ResponseFailure.build_from_invalid_request_object( InvalidRequestObject()) assert bool(response) is False
def test_response_failure_has_type_and_message(response_type, response_message): response = ResponseFailure(response_type, response_message) assert response.type == response_type assert response.message == response_message
def test_response_failure_is_false(response_type, response_message): assert bool(ResponseFailure(response_type, response_message)) is False