diff options
author | Justin Michalicek <jmichalicek@gmail.com> | 2016-07-07 17:20:31 -0400 |
---|---|---|
committer | Justin Michalicek <jmichalicek@gmail.com> | 2016-07-12 10:06:34 -0400 |
commit | f7807bdb52513dcbdab486a633ad5edeefa09e66 (patch) | |
tree | 777285b9ea2e1b87b83c51748fb9f42a15369f00 | |
parent | 66e7af93532890dcb8e43d8a701ca3b3eae51d4e (diff) | |
download | docker-py-f7807bdb52513dcbdab486a633ad5edeefa09e66.tar.gz |
Update build unit tests
* Test that the request from build when the client has
auth configs contains the correct X-Registry-Config header
* Test that BuildApiMixin._set_auth_headers() updates the passed
in headers dict with auth data from the client
* Test that BuildApiMixin._set_auth_headers() leaves headers dict intact
when there is no _auth_config on the client.
Signed-off-by: Justin Michalicek <jmichalicek@gmail.com>
-rw-r--r-- | tests/unit/build_test.py | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/tests/unit/build_test.py b/tests/unit/build_test.py index 414153e..8bd626b 100644 --- a/tests/unit/build_test.py +++ b/tests/unit/build_test.py @@ -2,8 +2,9 @@ import gzip import io import docker +from docker import auth -from .api_test import DockerClientTest +from .api_test import DockerClientTest, fake_request, url_prefix class BuildTest(DockerClientTest): @@ -83,8 +84,25 @@ class BuildTest(DockerClientTest): } } + expected_params = {'t': None, 'q': False, 'dockerfile': None, + 'rm': False, 'nocache': False, 'pull': False, + 'forcerm': False, + 'remote': 'https://github.com/docker-library/mongo'} + expected_headers = { + 'X-Registry-Config': auth.encode_header(self.client._auth_configs)} + self.client.build(path='https://github.com/docker-library/mongo') + fake_request.assert_called_with( + 'POST', + url_prefix + 'build', + stream=True, + data=None, + headers=expected_headers, + params=expected_params, + timeout=None + ) + def test_build_container_with_named_dockerfile(self): self.client.build('.', dockerfile='nameddockerfile') @@ -103,3 +121,44 @@ class BuildTest(DockerClientTest): 'foo': 'bar' }) ) + + def test__set_auth_headers_with_empty_dict_and_auth_configs(self): + self.client._auth_configs = { + 'https://example.com': { + 'user': 'example', + 'password': 'example', + 'email': 'example@example.com' + } + } + + headers = {} + expected_headers = { + 'X-Registry-Config': auth.encode_header(self.client._auth_configs)} + self.client._set_auth_headers(headers) + self.assertEqual(headers, expected_headers) + + def test__set_auth_headers_with_dict_and_auth_configs(self): + self.client._auth_configs = { + 'https://example.com': { + 'user': 'example', + 'password': 'example', + 'email': 'example@example.com' + } + } + + headers = {'foo': 'bar'} + expected_headers = { + 'foo': 'bar', + 'X-Registry-Config': auth.encode_header(self.client._auth_configs)} + + self.client._set_auth_headers(headers) + self.assertEqual(headers, expected_headers) + + def test__set_auth_headers_with_dict_and_no_auth_configs(self): + headers = {'foo': 'bar'} + expected_headers = { + 'foo': 'bar' + } + + self.client._set_auth_headers(headers) + self.assertEqual(headers, expected_headers) |