From 6a564971804ef91dfb3fe1c0c8c040dbd67c9e75 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Sat, 17 Feb 2018 17:49:39 +0900 Subject: [PATCH] Add assert_mock_multiple_calls_with_same_arguments test helper During the migration from mox to mock, it turns out there is case where some method is called multiple times with same parameters and it is common in openstack dashboard tests. This commit adds assert_mock_multiple_calls_with_same_arguments assertion method to ensure to check both call_count and arguments of all calls. Note that assert_has_calls just checks a subset of called arguments so it is better to check arguments of all calls. Part of blueprint mock-framework-in-unit-tests Change-Id: Id939e61718b0405a02a22a5ec8e55eda9554c545 --- openstack_dashboard/test/helpers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openstack_dashboard/test/helpers.py b/openstack_dashboard/test/helpers.py index 0edce3ecf6..0390b74885 100644 --- a/openstack_dashboard/test/helpers.py +++ b/openstack_dashboard/test/helpers.py @@ -446,6 +446,11 @@ class TestCase(horizon_helpers.TestCase): mock_args.update(args) return mock.Mock(**mock_args) + def assert_mock_multiple_calls_with_same_arguments( + self, mocked_method, count, expected_call): + self.assertEqual(count, mocked_method.call_count) + mocked_method.assert_has_calls([expected_call] * count) + class BaseAdminViewTests(TestCase): """Sets an active user with the "admin" role.