Remove usage of assert_called_once in mocks

This was never a real part of the mock api, but mock was happily mocking
it out and letting the tests pass. The new mock release made this
behaviour break, causing tests to fail on all patches. This patch
replaces instances of assert_called_once with an assert of the mock's
call_count.

Closes-Bug: #1473369
Co-Authored-By: Ian Cordasco <graffatcolmingov@gmail.com>
(cherry picked from commit df0e566f2a)

Conflicts:
	glance/tests/unit/async/test_taskflow_executor.py

Change-Id: I12ff85a9480d8000b0de54939c3be71458162a40
This commit is contained in:
Louis Taylor 2015-07-10 14:17:18 +00:00 committed by Thierry Carrez
parent d1f54b71b8
commit 899a8b9a77
3 changed files with 21 additions and 12 deletions

View File

@ -223,7 +223,7 @@ class TestImportTask(test_utils.BaseTestCase):
"%s.tasks_import" % image_path) "%s.tasks_import" % image_path)
self.assertFalse(os.path.exists(tmp_image_path)) self.assertFalse(os.path.exists(tmp_image_path))
self.assertTrue(os.path.exists(image_path)) self.assertTrue(os.path.exists(image_path))
umock.assert_called_once() self.assertEqual(1, umock.call_count)
with open(image_path) as ifile: with open(image_path) as ifile:
self.assertEqual(content, ifile.read()) self.assertEqual(content, ifile.read())

View File

@ -76,5 +76,5 @@ class TestTaskExecutor(test_utils.BaseTestCase):
self.executor.begin_processing(self.task.task_id) self.executor.begin_processing(self.task.task_id)
# assert the call # assert the call
load_mock.assert_called_once() self.assertEqual(1, load_mock.call_count)
engine.assert_called_once() self.assertEqual(1, engine.run.call_count)

View File

@ -301,21 +301,30 @@ class TestTasksController(test_utils.BaseTestCase):
"image_properties": {} "image_properties": {}
} }
} }
get_task_factory = mock.Mock()
mock_get_task_factory.return_value = get_task_factory
new_task = mock.Mock() new_task = mock.Mock()
mock_get_task_factory.new_task.return_value = new_task get_task_factory.new_task.return_value = new_task
mock_get_task_factory.new_task.run.return_value = mock.ANY
mock_get_task_executor_factory.new_task_exector.return_value = \ new_task.run.return_value = mock.ANY
mock.Mock()
mock_get_task_repo.add.return_value = mock.Mock() get_task_executor_factory = mock.Mock()
mock_get_task_executor_factory.return_value = get_task_executor_factory
get_task_executor_factory.new_task_executor.return_value = mock.Mock()
get_task_repo = mock.Mock()
mock_get_task_repo.return_value = get_task_repo
get_task_repo.add.return_value = mock.Mock()
# call # call
self.controller.create(request, task=task) self.controller.create(request, task=task)
# assert # assert
mock_get_task_factory.new_task.assert_called_once() self.assertEqual(1, get_task_factory.new_task.call_count)
mock_get_task_repo.add.assert_called_once() self.assertEqual(1, get_task_repo.add.call_count)
mock_get_task_executor_factory.new_task_exector.assert_called_once() self.assertEqual(
mock_get_task_factory.new_task.run.assert_called_once() 1, get_task_executor_factory.new_task_executor.call_count)
@mock.patch.object(glance.gateway.Gateway, 'get_task_factory') @mock.patch.object(glance.gateway.Gateway, 'get_task_factory')
def test_notifications_on_create(self, mock_get_task_factory): def test_notifications_on_create(self, mock_get_task_factory):