From 39ba2c5a7cb5a4f7cec1e5a28bd43dc95492b22d Mon Sep 17 00:00:00 2001 From: Mazz Mosley Date: Thu, 17 Sep 2015 15:33:58 +0100 Subject: [PATCH] Fix leaky tests It was mocking self.client but relying on the call to utils.create_host_config which was not mocked. So now that function has moved to also be on self.client we need to redefine the test boundary, up to where we would call docker-py, not the result of docker-py. Signed-off-by: Mazz Mosley --- tests/unit/cli_test.py | 13 +++++++++---- tests/unit/service_test.py | 10 +++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/unit/cli_test.py b/tests/unit/cli_test.py index 1fd9f529..d12f4195 100644 --- a/tests/unit/cli_test.py +++ b/tests/unit/cli_test.py @@ -144,8 +144,11 @@ class CLITestCase(unittest.TestCase): '--rm': None, '--name': None, }) - _, _, call_kwargs = mock_client.create_container.mock_calls[0] - self.assertEquals(call_kwargs['host_config']['RestartPolicy']['Name'], 'always') + + self.assertEquals( + mock_client.create_host_config.call_args[1]['restart_policy']['Name'], + 'always' + ) command = TopLevelCommand() mock_client = mock.create_autospec(docker.Client) @@ -170,8 +173,10 @@ class CLITestCase(unittest.TestCase): '--rm': True, '--name': None, }) - _, _, call_kwargs = mock_client.create_container.mock_calls[0] - self.assertFalse('RestartPolicy' in call_kwargs['host_config']) + + self.assertFalse( + mock_client.create_host_config.call_args[1].get('restart_policy') + ) def test_command_manula_and_service_ports_together(self): command = TopLevelCommand() diff --git a/tests/unit/service_test.py b/tests/unit/service_test.py index 7ba630fb..5f7ae948 100644 --- a/tests/unit/service_test.py +++ b/tests/unit/service_test.py @@ -543,13 +543,13 @@ class ServiceVolumesTest(unittest.TestCase): } } - create_options = service._get_container_create_options( + service._get_container_create_options( override_options={}, number=1, ) self.assertEqual( - set(create_options['host_config']['Binds']), + set(self.mock_client.create_host_config.call_args[1]['binds']), set([ '/host/path:/data1:rw', '/host/path:/data2:rw', @@ -581,14 +581,14 @@ class ServiceVolumesTest(unittest.TestCase): }, } - create_options = service._get_container_create_options( + service._get_container_create_options( override_options={}, number=1, previous_container=Container(self.mock_client, {'Id': '123123123'}), ) self.assertEqual( - create_options['host_config']['Binds'], + self.mock_client.create_host_config.call_args[1]['binds'], ['/mnt/sda1/host/path:/data:rw'], ) @@ -613,4 +613,4 @@ class ServiceVolumesTest(unittest.TestCase): ).create_container() self.assertEqual(len(create_calls), 1) - self.assertEqual(create_calls[0][1]['host_config']['Binds'], volumes) + self.assertEqual(self.mock_client.create_host_config.call_args[1]['binds'], volumes)