diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2014-10-13 22:40:11 -0500 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2014-10-14 15:37:23 -0500 |
| commit | ca783f46595a7d90cea0ad8491b65aa5f9370a04 (patch) | |
| tree | db0f6a59e4dcec4f2cc3ccc438f8c059aa1a9b4d /openstackclient/tests | |
| parent | 36212c43d880d0eaeb3df271cccb314802bf3372 (diff) | |
| download | python-openstackclient-ca783f46595a7d90cea0ad8491b65aa5f9370a04.tar.gz | |
Close files on image create
The file opened for --file was never closed. Close it if it is a
file object.
Change-Id: I7bd120a2413de42339771d01e8fd1894d38c3011
Diffstat (limited to 'openstackclient/tests')
| -rw-r--r-- | openstackclient/tests/image/v1/test_image.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/openstackclient/tests/image/v1/test_image.py b/openstackclient/tests/image/v1/test_image.py index 3f97b151..a0566930 100644 --- a/openstackclient/tests/image/v1/test_image.py +++ b/openstackclient/tests/image/v1/test_image.py @@ -139,14 +139,17 @@ class TestImageCreate(TestImage): self.assertEqual(image_fakes.IMAGE_columns, columns) self.assertEqual(image_fakes.IMAGE_data, data) - @mock.patch('six.moves.builtins.open') - def test_image_create_file(self, open_mock): + @mock.patch('openstackclient.image.v1.image.io.open', name='Open') + def test_image_create_file(self, mock_open): + mock_file = mock.MagicMock(name='File') + mock_open.return_value = mock_file + mock_open.read.return_value = image_fakes.image_data mock_exception = { 'find.side_effect': exceptions.CommandError('x'), 'get.side_effect': exceptions.CommandError('x'), } self.images_mock.configure_mock(**mock_exception) - open_mock.return_value = image_fakes.image_data + arglist = [ '--file', 'filer', '--unprotected', @@ -169,7 +172,11 @@ class TestImageCreate(TestImage): # DisplayCommandBase.take_action() returns two tuples columns, data = self.cmd.take_action(parsed_args) - open_mock.assert_called_with('filer', 'rb') + # Ensure input file is opened + mock_open.assert_called_with('filer', 'rb') + + # Ensure the input file is closed + mock_file.close.assert_called_with() # ImageManager.get(name) self.images_mock.get.assert_called_with(image_fakes.image_name) @@ -185,7 +192,7 @@ class TestImageCreate(TestImage): 'Alpha': '1', 'Beta': '2', }, - data=image_fakes.image_data, + data=mock_file, ) # Verify update() was not called, if it was show the args |
