summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2017-03-22 15:29:23 -0700
committerGitHub <noreply@github.com>2017-03-22 15:29:23 -0700
commitcb68acbaaef235f5dc7ee7e1744e8d88a6c10070 (patch)
tree8747886c45510305e0a9ad0adfe6a2ecc95c2328
parent3d8b20a9064980c0dc850cd02c91956f9ae79dcb (diff)
parente0e740438087971bc976a57cdb8d3044fb3fecd4 (diff)
downloaddocker-py-cb68acbaaef235f5dc7ee7e1744e8d88a6c10070.tar.gz
Merge pull request #1524 from alex-dr/fix-apierror-status
Fix APIError status_code property for client/server errors
-rw-r--r--docker/errors.py2
-rw-r--r--tests/unit/errors_test.py65
2 files changed, 66 insertions, 1 deletions
diff --git a/docker/errors.py b/docker/errors.py
index d9b197d..03b89c1 100644
--- a/docker/errors.py
+++ b/docker/errors.py
@@ -59,7 +59,7 @@ class APIError(requests.exceptions.HTTPError, DockerException):
@property
def status_code(self):
- if self.response:
+ if self.response is not None:
return self.response.status_code
def is_client_error(self):
diff --git a/tests/unit/errors_test.py b/tests/unit/errors_test.py
index 876ede3..b78af4e 100644
--- a/tests/unit/errors_test.py
+++ b/tests/unit/errors_test.py
@@ -1,5 +1,7 @@
import unittest
+import requests
+
from docker.errors import (APIError, DockerException,
create_unexpected_kwargs_error)
@@ -11,6 +13,69 @@ class APIErrorTest(unittest.TestCase):
except DockerException:
pass
+ def test_status_code_200(self):
+ """The status_code property is present with 200 response."""
+ resp = requests.Response()
+ resp.status_code = 200
+ err = APIError('', response=resp)
+ assert err.status_code == 200
+
+ def test_status_code_400(self):
+ """The status_code property is present with 400 response."""
+ resp = requests.Response()
+ resp.status_code = 400
+ err = APIError('', response=resp)
+ assert err.status_code == 400
+
+ def test_status_code_500(self):
+ """The status_code property is present with 500 response."""
+ resp = requests.Response()
+ resp.status_code = 500
+ err = APIError('', response=resp)
+ assert err.status_code == 500
+
+ def test_is_server_error_200(self):
+ """Report not server error on 200 response."""
+ resp = requests.Response()
+ resp.status_code = 200
+ err = APIError('', response=resp)
+ assert err.is_server_error() is False
+
+ def test_is_server_error_300(self):
+ """Report not server error on 300 response."""
+ resp = requests.Response()
+ resp.status_code = 300
+ err = APIError('', response=resp)
+ assert err.is_server_error() is False
+
+ def test_is_server_error_400(self):
+ """Report not server error on 400 response."""
+ resp = requests.Response()
+ resp.status_code = 400
+ err = APIError('', response=resp)
+ assert err.is_server_error() is False
+
+ def test_is_server_error_500(self):
+ """Report server error on 500 response."""
+ resp = requests.Response()
+ resp.status_code = 500
+ err = APIError('', response=resp)
+ assert err.is_server_error() is True
+
+ def test_is_client_error_500(self):
+ """Report not client error on 500 response."""
+ resp = requests.Response()
+ resp.status_code = 500
+ err = APIError('', response=resp)
+ assert err.is_client_error() is False
+
+ def test_is_client_error_400(self):
+ """Report client error on 400 response."""
+ resp = requests.Response()
+ resp.status_code = 400
+ err = APIError('', response=resp)
+ assert err.is_client_error() is True
+
class CreateUnexpectedKwargsErrorTest(unittest.TestCase):
def test_create_unexpected_kwargs_error_single(self):