Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
def error_handler(error):
    return make_error_response(error)
def error_handler(error):
    return make_error_response(error)