def __handle_task_not_found(exception: Exception) -> Response:
return Response(
response=dumps({
'msg': 'The requested task was not found.',
'status_code': '404'
}),
status=404,
mimetype="application/problem+json"
)
def test_task_not_found():
"""Test for functioning of custom handler for task not found"""
error = __handle_task_not_found(Exception)
assert error.status == '404 NOT FOUND'
assert error.mimetype == "application/problem+json"
response = json.loads(error.data.decode('utf-8'))
assert response == {
"msg": "The requested task was not found.",
"status_code": "404"
}
# CUSTOM ERRORS
class ResourceNotFound(ProblemException, NotFound, BaseException):
"""ResourceNotFound(404) error compatible with Connexion."""
def __init__(self, title=None, **kwargs):
super(ResourceNotFound, self).__init__(title=title, **kwargs)
def test_object_creation():
obj = ResourceNotFound()
assert obj.code == 404
assert obj.description == (
"The requested URL was not found on the server. "
"If you entered the URL manually please check your "
"spelling and try again."
)