11from http import HTTPStatus
22
3+ import pytest
34from servicelib .aiohttp import status
4- from servicelib .status_utils import (
5+ from servicelib .aiohttp .web_exceptions_extension import (
6+ STATUS_CODES_WITHOUT_AIOHTTP_EXCEPTION_CLASS ,
7+ get_all_aiohttp_http_exceptions ,
8+ )
9+ from servicelib .status_codes_utils import (
510 _INVALID_STATUS_CODE_MSG ,
611 get_code_description ,
712 get_code_display_name ,
813 get_http_status_codes ,
9- is_client_error ,
14+ is_1xx_informational ,
15+ is_2xx_success ,
16+ is_3xx_redirect ,
17+ is_4xx_client_error ,
18+ is_5xx_server_error ,
1019 is_error ,
11- is_informational ,
12- is_redirect ,
13- is_server_error ,
14- is_success ,
1520)
1621
1722
@@ -31,12 +36,12 @@ def test_description():
3136
3237def test_status_codes_checks ():
3338
34- assert is_informational (status .HTTP_102_PROCESSING )
35- assert is_success (status .HTTP_202_ACCEPTED )
36- assert is_redirect (status .HTTP_301_MOVED_PERMANENTLY )
39+ assert is_1xx_informational (status .HTTP_102_PROCESSING )
40+ assert is_2xx_success (status .HTTP_202_ACCEPTED )
41+ assert is_3xx_redirect (status .HTTP_301_MOVED_PERMANENTLY )
3742
38- assert is_client_error (status .HTTP_401_UNAUTHORIZED )
39- assert is_server_error (status .HTTP_503_SERVICE_UNAVAILABLE )
43+ assert is_4xx_client_error (status .HTTP_401_UNAUTHORIZED )
44+ assert is_5xx_server_error (status .HTTP_503_SERVICE_UNAVAILABLE )
4045
4146 assert is_error (status .HTTP_401_UNAUTHORIZED )
4247 assert is_error (status .HTTP_503_SERVICE_UNAVAILABLE )
@@ -45,7 +50,7 @@ def test_status_codes_checks():
4550def test_predicates_with_status ():
4651
4752 # in formational
48- assert get_http_status_codes (status , is_informational ) == [
53+ assert get_http_status_codes (status , is_1xx_informational ) == [
4954 status .HTTP_100_CONTINUE ,
5055 status .HTTP_101_SWITCHING_PROTOCOLS ,
5156 status .HTTP_102_PROCESSING ,
@@ -61,3 +66,15 @@ def test_predicates_with_status():
6166 for c in get_http_status_codes (status )
6267 if c != status .HTTP_306_RESERVED
6368 ]
69+
70+
71+ AIOHTTP_EXCEPTION_CLASSES_MAP = get_all_aiohttp_http_exceptions ()
72+
73+
74+ @pytest .mark .parametrize ("status_code" , get_http_status_codes (status ))
75+ def test_how_status_codes_map_to_aiohttp_exception_class (status_code ):
76+ aiohttp_exception_cls = AIOHTTP_EXCEPTION_CLASSES_MAP .get (status_code )
77+ if status_code in STATUS_CODES_WITHOUT_AIOHTTP_EXCEPTION_CLASS :
78+ assert aiohttp_exception_cls is None
79+ else :
80+ assert aiohttp_exception_cls is not None
0 commit comments