diff options
| author | Constantine Peresypkin <constantine.peresypkin@datarobot.com> | 2017-12-02 17:18:09 -0500 |
|---|---|---|
| committer | Constantine Peresypkin <constantine.peresypkin@datarobot.com> | 2017-12-18 17:15:48 +0200 |
| commit | b20f800db6f6521995268a5d7a4746c017fc6d9e (patch) | |
| tree | 029ab002e88821a641e0eae362074778d4d7906f /tests | |
| parent | 94e3d3dcb9d75d2302c5946d83ecae1e54a3b7c9 (diff) | |
| download | docker-py-b20f800db6f6521995268a5d7a4746c017fc6d9e.tar.gz | |
fixes create_api_error_from_http_exception()
`create_api_error_from_http_exception()` is never tested in the original code
and will fail miserably when fed with empty `HTTPError` object
see fixes in requests for this behaviour: https://github.com/requests/requests/pull/3179
Signed-off-by: Constantine Peresypkin <pconstantine@gmail.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/errors_test.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/unit/errors_test.py b/tests/unit/errors_test.py index 9678669..e27a9b1 100644 --- a/tests/unit/errors_test.py +++ b/tests/unit/errors_test.py @@ -3,7 +3,8 @@ import unittest import requests from docker.errors import (APIError, ContainerError, DockerException, - create_unexpected_kwargs_error) + create_unexpected_kwargs_error, + create_api_error_from_http_exception) from .fake_api import FAKE_CONTAINER_ID, FAKE_IMAGE_ID from .fake_api_client import make_fake_client @@ -78,6 +79,19 @@ class APIErrorTest(unittest.TestCase): err = APIError('', response=resp) assert err.is_client_error() is True + def test_create_error_from_exception(self): + resp = requests.Response() + resp.status_code = 500 + err = APIError('') + try: + resp.raise_for_status() + except requests.exceptions.HTTPError as e: + try: + create_api_error_from_http_exception(e) + except APIError as e: + err = e + assert err.is_server_error() is True + class ContainerErrorTest(unittest.TestCase): def test_container_without_stderr(self): |
