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
This commit is contained in:
Akihiro Motoki 2018-02-17 17:49:39 +09:00
parent 61ea0b6a76
commit 6a56497180
1 changed files with 5 additions and 0 deletions

View File

@ -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.