1+ import http
2+
13import pytest
24
35from ellar .common import get
@@ -33,23 +35,31 @@ def exception_():
3335@pytest .mark .parametrize (
3436 "exception, status_code, default_detail" ,
3537 [
36- (APIException , APIException .status_code , APIException .default_detail ),
38+ (
39+ APIException ,
40+ APIException .status_code ,
41+ http .HTTPStatus (APIException .status_code ).phrase ,
42+ ),
3743 (
3844 AuthenticationFailed ,
3945 AuthenticationFailed .status_code ,
40- AuthenticationFailed .default_detail ,
46+ "Incorrect authentication credentials." ,
47+ ),
48+ (
49+ NotAcceptable ,
50+ NotAcceptable .status_code ,
51+ http .HTTPStatus (NotAcceptable .status_code ).phrase ,
4152 ),
42- (NotAcceptable , NotAcceptable .status_code , NotAcceptable .default_detail ),
4353 (
4454 NotAuthenticated ,
4555 NotAuthenticated .status_code ,
46- NotAuthenticated .default_detail ,
56+ http . HTTPStatus ( NotAuthenticated .status_code ). phrase ,
4757 ),
48- (NotFound , NotFound .status_code , NotFound .default_detail ),
58+ (NotFound , NotFound .status_code , http . HTTPStatus ( NotFound .status_code ). phrase ),
4959 (
5060 PermissionDenied ,
5161 PermissionDenied .status_code ,
52- PermissionDenied .default_detail ,
62+ http . HTTPStatus ( PermissionDenied .status_code ). phrase ,
5363 ),
5464 ],
5565)
@@ -64,21 +74,17 @@ def test_api_exception(exception, status_code, default_detail):
6474
6575def test_unsupported_media_type_api_exception ():
6676 global _exception_runner
67- media_type = "application/json/sx"
68- _exception_runner = ExceptionRunner (UnsupportedMediaType , media_type = media_type )
77+ _exception_runner = ExceptionRunner (UnsupportedMediaType )
6978 response = client .get ("/exception" )
7079 data = response .json ()
7180 assert response .status_code == UnsupportedMediaType .status_code
72- assert data ["detail" ] == UnsupportedMediaType .default_detail .format (
73- media_type = media_type
74- )
81+ assert data ["detail" ] == http .HTTPStatus (UnsupportedMediaType .status_code ).phrase
7582
7683
7784def test_method_not_allowed_api_exception ():
7885 global _exception_runner
79- method = "GET"
80- _exception_runner = ExceptionRunner (MethodNotAllowed , method = method )
86+ _exception_runner = ExceptionRunner (MethodNotAllowed )
8187 response = client .get ("/exception" )
8288 data = response .json ()
8389 assert response .status_code == MethodNotAllowed .status_code
84- assert data ["detail" ] == MethodNotAllowed . default_detail . format ( method = method )
90+ assert data ["detail" ] == http . HTTPStatus ( MethodNotAllowed . status_code ). phrase
0 commit comments