Merge "Set any_order to True in some unit tests"

This commit is contained in:
Jenkins 2014-07-22 15:34:04 +00:00 committed by Gerrit Code Review
commit de68be5120
3 changed files with 31 additions and 36 deletions

View File

@ -132,9 +132,11 @@ class ContextManagerTestCase(test.TestCase):
mock_get.assert_has_calls([ mock_get.assert_has_calls([
mock.call("a"), mock.call("a"),
mock.call("b"), mock.call("b"),
], any_order=True)
mock_get.assert_has_calls([
mock.call()(context), mock.call()(context),
mock.call()(context) mock.call()(context),
]) ], any_order=True)
@mock.patch("rally.benchmark.context.base.Context.get_by_name") @mock.patch("rally.benchmark.context.base.Context.get_by_name")
def test_validate(self, mock_get): def test_validate(self, mock_get):
@ -144,11 +146,10 @@ class ContextManagerTestCase(test.TestCase):
} }
base.ContextManager.validate(config) base.ContextManager.validate(config)
for ctx in ("ctx1", "ctx2"):
mock_get.assert_has_calls([ mock_get.assert_has_calls([
mock.call("ctx1"), mock.call(ctx),
mock.call().validate(config["ctx1"], non_hidden=False), mock.call().validate(config[ctx], non_hidden=False),
mock.call("ctx2"),
mock.call().validate(config["ctx2"], non_hidden=False)
]) ])
@mock.patch("rally.benchmark.context.base.Context.get_by_name") @mock.patch("rally.benchmark.context.base.Context.get_by_name")
@ -159,13 +160,11 @@ class ContextManagerTestCase(test.TestCase):
} }
base.ContextManager.validate_semantic(config) base.ContextManager.validate_semantic(config)
for ctx in ("ctx1", "ctx2"):
mock_get.assert_has_calls([ mock_get.assert_has_calls([
mock.call("ctx1"), mock.call(ctx),
mock.call().validate_semantic(config["ctx1"], admin=None, mock.call().validate_semantic(config[ctx], admin=None,
users=None, task=None), users=None, task=None),
mock.call("ctx2"),
mock.call().validate_semantic(config["ctx2"], admin=None,
users=None, task=None)
]) ])
@mock.patch("rally.benchmark.context.base.Context.get_by_name") @mock.patch("rally.benchmark.context.base.Context.get_by_name")
@ -176,11 +175,10 @@ class ContextManagerTestCase(test.TestCase):
} }
base.ContextManager.validate(config, non_hidden=True) base.ContextManager.validate(config, non_hidden=True)
for ctx in ("ctx1", "ctx2"):
mock_get.assert_has_calls([ mock_get.assert_has_calls([
mock.call("ctx1"), mock.call(ctx),
mock.call().validate(config["ctx1"], non_hidden=True), mock.call().validate(config[ctx], non_hidden=True),
mock.call("ctx2"),
mock.call().validate(config["ctx2"], non_hidden=True)
]) ])
def test_validate__non_existing_context(self): def test_validate__non_existing_context(self):

View File

@ -23,16 +23,11 @@ from tests import test
class RoleGeneratorTestCase(test.TestCase): class RoleGeneratorTestCase(test.TestCase):
def create_default_roles_and_patch_add_remove_fuinctions(self, fc): def create_default_roles_and_patch_add_remove_functions(self, fc):
fc.keystone().roles.add_user_role = mock.MagicMock() fc.keystone().roles.add_user_role = mock.MagicMock()
fc.keystone().roles.remove_user_role = mock.MagicMock() fc.keystone().roles.remove_user_role = mock.MagicMock()
fc.keystone().roles.create("r1", "test_role1")
self.assertEqual(0, len(fc.keystone().roles.list())) fc.keystone().roles.create("r2", "test_role2")
default_roles = [{"id": "r1", "name": "test_role1"},
{"id": "r2", "name": "test_role2"}]
fc.keystone().roles.create(*default_roles[0].values())
fc.keystone().roles.create(*default_roles[1].values())
self.assertEqual(2, len(fc.keystone().roles.list())) self.assertEqual(2, len(fc.keystone().roles.list()))
@property @property
@ -52,7 +47,7 @@ class RoleGeneratorTestCase(test.TestCase):
def test_add_role(self, mock_osclients): def test_add_role(self, mock_osclients):
fc = fakes.FakeClients() fc = fakes.FakeClients()
mock_osclients.Clients.return_value = fc mock_osclients.Clients.return_value = fc
self.create_default_roles_and_patch_add_remove_fuinctions(fc) self.create_default_roles_and_patch_add_remove_functions(fc)
ctx = roles.RoleGenerator(self.context) ctx = roles.RoleGenerator(self.context)
ctx.context["users"] = [{"id": "u1", "tenant_id": "t1"}, ctx.context["users"] = [{"id": "u1", "tenant_id": "t1"},
@ -67,7 +62,7 @@ class RoleGeneratorTestCase(test.TestCase):
def test_add_role_which_does_not_exist(self, mock_osclients): def test_add_role_which_does_not_exist(self, mock_osclients):
fc = fakes.FakeClients() fc = fakes.FakeClients()
mock_osclients.Clients.return_value = fc mock_osclients.Clients.return_value = fc
self.create_default_roles_and_patch_add_remove_fuinctions(fc) self.create_default_roles_and_patch_add_remove_functions(fc)
ctx = roles.RoleGenerator(self.context) ctx = roles.RoleGenerator(self.context)
ctx.context["users"] = [{"id": "u1", "tenant_id": "t1"}, ctx.context["users"] = [{"id": "u1", "tenant_id": "t1"},
@ -96,7 +91,7 @@ class RoleGeneratorTestCase(test.TestCase):
def test_setup_and_cleanup(self, mock_osclients): def test_setup_and_cleanup(self, mock_osclients):
fc = fakes.FakeClients() fc = fakes.FakeClients()
mock_osclients.Clients.return_value = fc mock_osclients.Clients.return_value = fc
self.create_default_roles_and_patch_add_remove_fuinctions(fc) self.create_default_roles_and_patch_add_remove_functions(fc)
with roles.RoleGenerator(self.context) as ctx: with roles.RoleGenerator(self.context) as ctx:
ctx.context["users"] = [{"id": "u1", "tenant_id": "t1"}, ctx.context["users"] = [{"id": "u1", "tenant_id": "t1"},

View File

@ -126,9 +126,11 @@ class BenchmarkEngineTestCase(test.TestCase):
config = {"sca": [{"context": "a"}], "scb": [{"runner": "b"}]} config = {"sca": [{"context": "a"}], "scb": [{"runner": "b"}]}
eng = engine.BenchmarkEngine(mock.MagicMock(), mock.MagicMock()) eng = engine.BenchmarkEngine(mock.MagicMock(), mock.MagicMock())
eng._validate_config_syntax(config) eng._validate_config_syntax(config)
mock_runner.assert_has_calls([mock.call({}), mock.call("b")]) mock_runner.assert_has_calls([mock.call({}), mock.call("b")],
any_order=True)
mock_context.assert_has_calls([mock.call("a", non_hidden=True), mock_context.assert_has_calls([mock.call("a", non_hidden=True),
mock.call({}, non_hidden=True)]) mock.call({}, non_hidden=True)],
any_order=True)
@mock.patch("rally.benchmark.engine.base_runner.ScenarioRunner") @mock.patch("rally.benchmark.engine.base_runner.ScenarioRunner")
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.validate") @mock.patch("rally.benchmark.engine.base_ctx.ContextManager.validate")
@ -218,7 +220,7 @@ class BenchmarkEngineTestCase(test.TestCase):
mock.call(admin, user, "a", 1, fake_task, config["a"][1]), mock.call(admin, user, "a", 1, fake_task, config["a"][1]),
mock.call(admin, user, "b", 0, fake_task, config["b"][0]) mock.call(admin, user, "b", 0, fake_task, config["b"][0])
] ]
mock_helper.assert_has_calls(expected_calls) mock_helper.assert_has_calls(expected_calls, any_order=True)
@mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results") @mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results")
def test_run__update_status(self, mock_consume): def test_run__update_status(self, mock_consume):