Example #1
0
    def test_when_invalid_parameters_is_raised(self):
        expected_status_code = 400
        expected_message = ["Invalid parameters: parameter"]
        exception = InvalidParametersError(['parameter'])

        response = make_error_response(exception)

        self.assertResponse(response, expected_status_code, expected_message)
Example #2
0
    def test_when_generic_exception_is_raised(self):
        expected_status_code = 500
        expected_message = ["unexpected error during request: error message"]
        exception = Exception("error message")

        response = make_error_response(exception)

        self.assertResponse(response, expected_status_code, expected_message)
Example #3
0
    def test_when_element_not_exists_is_raised(self):
        expected_status_code = 404
        expected_message = ["element with id=1 does not exist"]
        exception = ElementNotExistsError('element', id=1)

        response = make_error_response(exception)

        self.assertResponse(response, expected_status_code, expected_message)
Example #4
0
    def test_when_association_not_exists_error_is_raised(self):
        expected_status_code = 404
        expected_message = ["association error"]
        exception = AssociationNotExistsError("association error")

        response = make_error_response(exception)

        self.assertResponse(response, expected_status_code, expected_message)
Example #5
0
    def test_when_element_deletion_error_is_raised(self):
        expected_status_code = 400
        expected_message = ["Error while deleting user: error message"]
        exception = ElementDeletionError('user', 'error message')

        response = make_error_response(exception)

        self.assertResponse(response, expected_status_code, expected_message)
Example #6
0
    def test_when_element_already_error_is_raised(self):
        expected_status_code = 400
        expected_message = ["user johndoe already exists"]
        exception = ElementAlreadyExistsError('user', 'johndoe')

        response = make_error_response(exception)

        self.assertResponse(response, expected_status_code, expected_message)
Example #7
0
    def test_when_nonexistent_parameters_error_is_raised(self):
        expected_status_code = 400
        expected_message = [
            "Nonexistent parameters: username johndoe does not exist"
        ]
        exception = NonexistentParametersError(username='******')

        response = make_error_response(exception)

        self.assertResponse(response, expected_status_code, expected_message)
Example #8
0
def error_handler(error):
    return make_error_response(error)
Example #9
0
def error_handler(error):
    return make_error_response(error)