1111 parse_problem_details ,
1212)
1313from pip ._internal .network .utils import raise_for_status
14+
1415from tests .lib .requests_mocks import MockResponse
1516
1617
@@ -28,11 +29,13 @@ def test_from_dict(self) -> None:
2829 assert problem .detail == "Resource not found"
2930
3031 def test_from_json (self ) -> None :
31- json_str = json .dumps ({
32- "status" : 404 ,
33- "title" : "Not Found" ,
34- "detail" : "Resource not found" ,
35- })
32+ json_str = json .dumps (
33+ {
34+ "status" : 404 ,
35+ "title" : "Not Found" ,
36+ "detail" : "Resource not found" ,
37+ }
38+ )
3639
3740 problem = ProblemDetails .from_json (json_str )
3841 assert problem .status == 404
@@ -51,6 +54,7 @@ def test_string_representation(self) -> None:
5154 assert "403" in str_repr
5255 assert "API token" in str_repr
5356
57+
5458class TestIsProblemDetailsResponse :
5559 def test_detects_problem_json_content_type (self ) -> None :
5660 resp = MockResponse (b"" )
@@ -76,6 +80,7 @@ def test_does_not_detect_without_content_type(self) -> None:
7680
7781 assert is_problem_details_response (resp ) is False
7882
83+
7984class TestParseProblemDetails :
8085 def test_parses_valid_problem_details (self ) -> None :
8186 problem_data = {
@@ -107,6 +112,7 @@ def test_handles_malformed_json(self) -> None:
107112 problem = parse_problem_details (resp )
108113 assert problem is None
109114
115+
110116@pytest .mark .parametrize (
111117 "status_code, title, detail" ,
112118 [
@@ -115,7 +121,6 @@ def test_handles_malformed_json(self) -> None:
115121 (403 , "Forbidden" , "Access denied to this resource" ),
116122 ],
117123)
118-
119124class TestRaiseForStatusWithProblemDetails :
120125 def test_raises_http_problem_details_error (
121126 self , status_code : int , title : str , detail : str
@@ -146,7 +151,6 @@ def test_raises_http_problem_details_error(
146151 (403 , "Client Error" ),
147152 ],
148153)
149-
150154class TestRaiseForStatusBackwardCompatibility :
151155 def test_raises_network_connection_error (
152156 self , status_code : int , error_type : str
0 commit comments