Skip to content

Commit 219c521

Browse files
committed
Regression 443 test: relax status-code check
This test was testing for a 500 status, but this status is actually a bug in the API (as it's due to an invalid request), and the API should actually return a 400 status. To make this test handle both situations, relax the test to accept either a 4xx or 5xx status. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 5455c04 commit 219c521

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

docker/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def status_code(self):
6363
if self.response is not None:
6464
return self.response.status_code
6565

66+
def is_error(self):
67+
return self.is_client_error() or self.is_server_error()
68+
6669
def is_client_error(self):
6770
if self.status_code is None:
6871
return False

tests/integration/regression_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_443_handle_nonchunked_response_in_stream(self):
1414
with pytest.raises(docker.errors.APIError) as exc:
1515
for line in self.client.build(fileobj=dfile, tag="a/b/c"):
1616
pass
17-
assert exc.value.response.status_code == 500
17+
assert exc.value.is_error()
1818
dfile.close()
1919

2020
def test_542_truncate_ids_client_side(self):

tests/unit/errors_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ def test_is_client_error_400(self):
7979
err = APIError('', response=resp)
8080
assert err.is_client_error() is True
8181

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+
82103
def test_create_error_from_exception(self):
83104
resp = requests.Response()
84105
resp.status_code = 500

0 commit comments

Comments
 (0)