1313from aiohttp .test_utils import make_mocked_request
1414from servicelib .aiohttp import status
1515from servicelib .mimetype_constants import MIMETYPE_APPLICATION_JSON
16+ from servicelib .status_codes_utils import get_code_display_name
1617from simcore_service_webserver .errors import WebServerBaseError
1718from simcore_service_webserver .exception_handling ._base import (
1819 ExceptionHandlingContextManager ,
2829# Some custom errors in my service
2930
3031
31- class BaseError (WebServerBaseError ):
32- ...
32+ class BaseError (WebServerBaseError ): ...
3333
3434
35- class OneError (BaseError ):
36- ...
35+ class OneError (BaseError ): ...
3736
3837
39- class OtherError (BaseError ):
40- ...
38+ class OtherError (BaseError ): ...
4139
4240
4341@pytest .fixture
@@ -58,7 +56,7 @@ async def test_factory__create_exception_handler_from_http_error(
5856 response = await one_error_to_404 (fake_request , caught )
5957 assert response .status == status .HTTP_404_NOT_FOUND
6058 assert response .text is not None
61- assert "one error message" in response .reason
59+ assert response . reason == get_code_display_name ( response .status )
6260 assert response .content_type == MIMETYPE_APPLICATION_JSON
6361
6462
@@ -82,9 +80,7 @@ async def test_handling_different_exceptions_with_context(
8280 response = cm .get_response_or_none ()
8381 assert response is not None
8482 assert response .status == status .HTTP_400_BAD_REQUEST
85- assert response .reason == exc_to_http_error_map [OneError ].msg_template .format (
86- code = "WebServerBaseError.BaseError.OneError"
87- )
83+ assert response .reason == get_code_display_name (response .status )
8884 assert not caplog .records
8985
9086 # unhandled -> reraises
@@ -103,9 +99,7 @@ async def test_handling_different_exceptions_with_context(
10399 response = cm .get_response_or_none ()
104100 assert response is not None
105101 assert response .status == status .HTTP_500_INTERNAL_SERVER_ERROR
106- assert response .reason == exc_to_http_error_map [OtherError ].msg_template .format (
107- code = "WebServerBaseError.BaseError.OtherError"
108- )
102+ assert response .reason == get_code_display_name (response .status )
109103 assert caplog .records , "Expected 5XX troubleshooting logged as error"
110104 assert caplog .records [0 ].levelno == logging .ERROR
111105
0 commit comments