Skip to content

Commit 3649da4

Browse files
committed
adds tests
1 parent 36f7144 commit 3649da4

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import json
2+
from typing import Any
3+
4+
import pytest
5+
import servicelib.aiohttp
6+
from pydantic import BaseModel
7+
from pytest_simcore.pydantic_models import walk_model_examples_in_package
8+
9+
10+
@pytest.mark.parametrize(
11+
"model_cls, example_name, example_data",
12+
walk_model_examples_in_package(servicelib.aiohttp),
13+
)
14+
def test_all_models_config_examples_in_servicelib_aiohttp_package(
15+
model_cls: type[BaseModel], example_name: int, example_data: Any
16+
):
17+
assert model_cls.parse_obj(
18+
example_data
19+
), f"Failed {example_name} : {json.dumps(example_data)}"

packages/service-library/tests/aiohttp/test_status_utils.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
from http import HTTPStatus
22

3+
import pytest
34
from 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

3237
def 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():
4550
def 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

Comments
 (0)