async def test_http_exception_handler_returns_as_expected(mock_json_response): detail = "fooDetail" exception_stub = NonCallableMagicMock() exception_stub.detail = detail exception_stub.status_code = 500 response = await http_exception_handler(NonCallableMagicMock(), exception_stub) mock_json_response.assert_called_once_with( status_code=500, content={ "errors": [{ "status": "500", "code": "InternalServerError", "title": "Internal Server Error", "detail": detail, }] }, ) assert isinstance(response, JSONResponse)
async def test_http_exception_handler_method_not_allowed_returns_405( mock_json_response): exception_stub = NonCallableMagicMock() exception_stub.detail = "Method Not Allowed" exception_stub.status_code = 405 response = await http_exception_handler(NonCallableMagicMock(), exception_stub) mock_json_response.assert_called_once_with( status_code=405, content={ "errors": [{ "status": "405", "code": "MethodNotAllowed", "title": "Method Not Allowed", "detail": "Method Not Allowed", }] }, ) assert isinstance(response, JSONResponse)
async def test_http_exception_handler_resource_not_found_returns_404( mock_json_response): exception_stub = NonCallableMagicMock() exception_stub.detail = "not found" exception_stub.status_code = 404 response = await http_exception_handler(NonCallableMagicMock(), exception_stub) mock_json_response.assert_called_once_with( status_code=404, content={ "errors": [{ "status": "404", "code": "NotFound", "title": "Not Found", "detail": "Missing Resource URI", }] }, ) assert isinstance(response, JSONResponse)
async def test_notfound_exception_handler_returns_as_expected( mock_json_response): detail = "Detail" exception_stub = NonCallableMagicMock() exception_stub.detail = detail exception_stub.status_code = 404 response = await notfound_exception_handler(NonCallableMagicMock(), exception_stub) mock_json_response.assert_called_once_with( status_code=404, content={ "errors": [{ "status": "404", "code": "NotFound", "title": "Not Found", "detail": detail, }] }, ) assert isinstance(response, JSONResponse)