Unverified Kaydet (Commit) 1073b736 authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) GitHub

Merge pull request #2216 from thaJeztah/fix_status_code_check

Regression 443 test: relax status-code check
...@@ -63,6 +63,9 @@ class APIError(requests.exceptions.HTTPError, DockerException): ...@@ -63,6 +63,9 @@ class APIError(requests.exceptions.HTTPError, DockerException):
if self.response is not None: if self.response is not None:
return self.response.status_code return self.response.status_code
def is_error(self):
return self.is_client_error() or self.is_server_error()
def is_client_error(self): def is_client_error(self):
if self.status_code is None: if self.status_code is None:
return False return False
......
...@@ -14,7 +14,7 @@ class TestRegressions(BaseAPIIntegrationTest): ...@@ -14,7 +14,7 @@ class TestRegressions(BaseAPIIntegrationTest):
with pytest.raises(docker.errors.APIError) as exc: with pytest.raises(docker.errors.APIError) as exc:
for line in self.client.build(fileobj=dfile, tag="a/b/c"): for line in self.client.build(fileobj=dfile, tag="a/b/c"):
pass pass
assert exc.value.response.status_code == 500 assert exc.value.is_error()
dfile.close() dfile.close()
def test_542_truncate_ids_client_side(self): def test_542_truncate_ids_client_side(self):
......
...@@ -79,6 +79,27 @@ class APIErrorTest(unittest.TestCase): ...@@ -79,6 +79,27 @@ class APIErrorTest(unittest.TestCase):
err = APIError('', response=resp) err = APIError('', response=resp)
assert err.is_client_error() is True assert err.is_client_error() is True
def test_is_error_300(self):
"""Report no error on 300 response."""
resp = requests.Response()
resp.status_code = 300
err = APIError('', response=resp)
assert err.is_error() is False
def test_is_error_400(self):
"""Report error on 400 response."""
resp = requests.Response()
resp.status_code = 400
err = APIError('', response=resp)
assert err.is_error() is True
def test_is_error_500(self):
"""Report error on 500 response."""
resp = requests.Response()
resp.status_code = 500
err = APIError('', response=resp)
assert err.is_error() is True
def test_create_error_from_exception(self): def test_create_error_from_exception(self):
resp = requests.Response() resp = requests.Response()
resp.status_code = 500 resp.status_code = 500
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment