File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,9 @@ def status_code(self):
63
63
if self .response is not None :
64
64
return self .response .status_code
65
65
66
+ def is_error (self ):
67
+ return self .is_client_error () or self .is_server_error ()
68
+
66
69
def is_client_error (self ):
67
70
if self .status_code is None :
68
71
return False
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ def test_443_handle_nonchunked_response_in_stream(self):
14
14
with pytest .raises (docker .errors .APIError ) as exc :
15
15
for line in self .client .build (fileobj = dfile , tag = "a/b/c" ):
16
16
pass
17
- assert exc .value .response . status_code == 500
17
+ assert exc .value .is_error ()
18
18
dfile .close ()
19
19
20
20
def test_542_truncate_ids_client_side (self ):
Original file line number Diff line number Diff line change @@ -79,6 +79,27 @@ def test_is_client_error_400(self):
79
79
err = APIError ('' , response = resp )
80
80
assert err .is_client_error () is True
81
81
82
+ def test_is_error_300 (self ):
83
+ """Report no error on 300 response."""
84
+ resp = requests .Response ()
85
+ resp .status_code = 300
86
+ err = APIError ('' , response = resp )
87
+ assert err .is_error () is False
88
+
89
+ def test_is_error_400 (self ):
90
+ """Report error on 400 response."""
91
+ resp = requests .Response ()
92
+ resp .status_code = 400
93
+ err = APIError ('' , response = resp )
94
+ assert err .is_error () is True
95
+
96
+ def test_is_error_500 (self ):
97
+ """Report error on 500 response."""
98
+ resp = requests .Response ()
99
+ resp .status_code = 500
100
+ err = APIError ('' , response = resp )
101
+ assert err .is_error () is True
102
+
82
103
def test_create_error_from_exception (self ):
83
104
resp = requests .Response ()
84
105
resp .status_code = 500
You can’t perform that action at this time.
0 commit comments