diff --git a/glance/tests/unit/async/flows/test_import.py b/glance/tests/unit/async/flows/test_import.py index 7acd599d4d..70f790c226 100644 --- a/glance/tests/unit/async/flows/test_import.py +++ b/glance/tests/unit/async/flows/test_import.py @@ -223,7 +223,7 @@ class TestImportTask(test_utils.BaseTestCase): "%s.tasks_import" % image_path) self.assertFalse(os.path.exists(tmp_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: self.assertEqual(content, ifile.read()) diff --git a/glance/tests/unit/async/test_taskflow_executor.py b/glance/tests/unit/async/test_taskflow_executor.py index 678291801e..e6453fde88 100644 --- a/glance/tests/unit/async/test_taskflow_executor.py +++ b/glance/tests/unit/async/test_taskflow_executor.py @@ -76,5 +76,5 @@ class TestTaskExecutor(test_utils.BaseTestCase): self.executor.begin_processing(self.task.task_id) # assert the call - load_mock.assert_called_once() - engine.assert_called_once() + self.assertEqual(1, load_mock.call_count) + self.assertEqual(1, engine.run.call_count) diff --git a/glance/tests/unit/v2/test_tasks_resource.py b/glance/tests/unit/v2/test_tasks_resource.py index 103b27c3f7..96c1180d08 100644 --- a/glance/tests/unit/v2/test_tasks_resource.py +++ b/glance/tests/unit/v2/test_tasks_resource.py @@ -301,21 +301,30 @@ class TestTasksController(test_utils.BaseTestCase): "image_properties": {} } } + get_task_factory = mock.Mock() + mock_get_task_factory.return_value = get_task_factory + new_task = mock.Mock() - mock_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 = \ - mock.Mock() - mock_get_task_repo.add.return_value = mock.Mock() + get_task_factory.new_task.return_value = new_task + + new_task.run.return_value = mock.ANY + + 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 self.controller.create(request, task=task) # assert - mock_get_task_factory.new_task.assert_called_once() - mock_get_task_repo.add.assert_called_once() - mock_get_task_executor_factory.new_task_exector.assert_called_once() - mock_get_task_factory.new_task.run.assert_called_once() + self.assertEqual(1, get_task_factory.new_task.call_count) + self.assertEqual(1, get_task_repo.add.call_count) + self.assertEqual( + 1, get_task_executor_factory.new_task_executor.call_count) @mock.patch.object(glance.gateway.Gateway, 'get_task_factory') def test_notifications_on_create(self, mock_get_task_factory):