1010
1111
1212def test_http_error ():
13- exception = MPTHttpError (status_code = 400 , text = "Content" )
13+ exception = MPTHttpError (status_code = 400 , message = "Bad request" , body = "Content" )
1414
1515 assert exception .status_code == 400
16- assert exception .text == "Content"
16+ assert exception .body == "Content"
17+ assert str (exception ) == "HTTP 400: Bad request"
18+
19+
20+ def test_http_error_not_found_from_mpt (): # noqa: WPS218
21+ status_code = 400 # changed from 404 for testing purposes
22+ api_status_code = 404
23+ payload = {"message" : "Resource not found" , "statusCode" : api_status_code }
24+ message = (
25+ "Client error '404 Resource Not Found' for url "
26+ "'https://api.s1.show/public/public/v1/catalog/products?limit=100&offset=0'\n "
27+ "For more information check: "
28+ "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404"
29+ )
30+
31+ exception = MPTAPIError (status_code = status_code , message = message , payload = payload )
32+
33+ assert exception .status_code == status_code
34+ assert exception .payload == payload
35+ assert exception .status == api_status_code
36+ assert exception .title == "Resource not found"
37+ assert exception .detail == message
38+ assert exception .trace_id is None
39+ assert exception .errors is None
40+ assert str (exception ) == f"404 Resource not found - { message } (no-trace-id)"
1741
1842
1943def test_api_error (): # noqa: WPS218
@@ -24,7 +48,7 @@ def test_api_error(): # noqa: WPS218
2448 "traceId" : "abc123" ,
2549 "errors" : "Some error details" ,
2650 }
27- exception = MPTAPIError (status_code = 400 , payload = payload )
51+ exception = MPTAPIError (status_code = 400 , message = "Bad Request" , payload = payload )
2852
2953 assert exception .status_code == 400
3054 assert exception .payload == payload
@@ -43,7 +67,7 @@ def test_api_error_str_and_repr():
4367 "traceId" : "abc123" ,
4468 "errors" : "Some error details" ,
4569 }
46- exception = MPTAPIError (status_code = 400 , payload = payload )
70+ exception = MPTAPIError (status_code = 400 , message = "Bad request" , payload = payload )
4771
4872 assert str (exception ) == '400 Bad Request - Invalid input (abc123)\n "Some error details"'
4973 assert repr (exception ) == (
@@ -60,12 +84,12 @@ def test_api_error_str_no_errors():
6084 "traceId" : "abc123" ,
6185 }
6286
63- exception = MPTAPIError (status_code = 400 , payload = payload )
87+ exception = MPTAPIError (status_code = 400 , message = "Bad request" , payload = payload )
6488
6589 assert str (exception ) == "400 Bad Request - Invalid input (abc123)"
6690
6791
68- def test_transform_http_status_exception ():
92+ def test_transform_http_status_exception_api ():
6993 payload = {
7094 "status" : "400" ,
7195 "title" : "Bad Request" ,
@@ -88,17 +112,18 @@ def test_transform_http_status_exception():
88112 assert err .payload == payload
89113
90114
91- def test_transform_http_status_exception_json ():
115+ def test_transform_http_status_exception ():
92116 response = Response (
93117 status_code = 500 ,
94118 request = Request ("GET" , "http://test" ),
95119 content = b"Internal Server Error" ,
96120 headers = {"content-type" : "text/plain" },
97121 )
98- exc = HTTPStatusError ("error " , request = response .request , response = response )
122+ exc = HTTPStatusError ("Error message " , request = response .request , response = response )
99123
100124 err = transform_http_status_exception (exc )
101125
102126 assert isinstance (err , MPTHttpError )
103127 assert err .status_code == 500
104- assert err .text == "Internal Server Error"
128+ assert err .body == "Internal Server Error"
129+ assert str (err ) == "HTTP 500: Error message"
0 commit comments