diff options
author | Anca Iordache <anca.iordache@docker.com> | 2020-01-17 19:25:55 +0100 |
---|---|---|
committer | Anca Iordache <anca.iordache@docker.com> | 2020-02-05 14:49:42 +0100 |
commit | 64fdb32ae801ef5a49541e421f05678767677bae (patch) | |
tree | 88378004cf021c827a8399bdb49ae02a40fb12cf /tests/unit | |
parent | f2e09ae63287dd812ceaf936513ccf836392fab1 (diff) | |
download | docker-py-64fdb32ae801ef5a49541e421f05678767677bae.tar.gz |
Implement context management, lifecycle and unittests.
Signed-off-by: Anca Iordache <anca.iordache@docker.com>
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/context_test.py | 45 | ||||
-rw-r--r-- | tests/unit/errors_test.py | 20 |
2 files changed, 55 insertions, 10 deletions
diff --git a/tests/unit/context_test.py b/tests/unit/context_test.py new file mode 100644 index 0000000..5e88c69 --- /dev/null +++ b/tests/unit/context_test.py @@ -0,0 +1,45 @@ +import unittest +import docker +import pytest +from docker.constants import DEFAULT_UNIX_SOCKET +from docker.constants import DEFAULT_NPIPE +from docker.constants import IS_WINDOWS_PLATFORM +from docker.context import ContextAPI, Context + + +class BaseContextTest(unittest.TestCase): + @pytest.mark.skipif( + IS_WINDOWS_PLATFORM, reason='Linux specific path check' + ) + def test_url_compatibility_on_linux(self): + c = Context("test") + assert c.Host == DEFAULT_UNIX_SOCKET.strip("http+") + + @pytest.mark.skipif( + not IS_WINDOWS_PLATFORM, reason='Windows specific path check' + ) + def test_url_compatibility_on_windows(self): + c = Context("test") + assert c.Host == DEFAULT_NPIPE + + def test_fail_on_default_context_create(self): + with pytest.raises(docker.errors.ContextException): + ContextAPI.create_context("default") + + def test_default_in_context_list(self): + found = False + ctx = ContextAPI.contexts() + for c in ctx: + if c.Name == "default": + found = True + assert found is True + + def test_get_current_context(self): + assert ContextAPI.get_current_context().Name == "default" + + def test_context_inspect_without_params(self): + ctx = ContextAPI.inspect_context() + assert ctx["Name"] == "default" + assert ctx["Metadata"]["StackOrchestrator"] == "swarm" + assert ctx["Endpoints"]["docker"]["Host"] in [ + DEFAULT_NPIPE, DEFAULT_UNIX_SOCKET.strip("http+")] diff --git a/tests/unit/errors_test.py b/tests/unit/errors_test.py index 2134f86..54c2ba8 100644 --- a/tests/unit/errors_test.py +++ b/tests/unit/errors_test.py @@ -101,17 +101,17 @@ class APIErrorTest(unittest.TestCase): assert err.is_error() is True def test_create_error_from_exception(self): - resp = requests.Response() - resp.status_code = 500 - err = APIError('') + resp = requests.Response() + resp.status_code = 500 + err = APIError('') + try: + resp.raise_for_status() + except requests.exceptions.HTTPError as e: 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 + create_api_error_from_http_exception(e) + except APIError as e: + err = e + assert err.is_server_error() is True class ContainerErrorTest(unittest.TestCase): |