Skip to content

Commit

Permalink
Merge "Set any_order to True in some unit tests"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jul 22, 2014
2 parents 4497b2f + 2720173 commit de68be5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
42 changes: 20 additions & 22 deletions tests/benchmark/context/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ def test_run(self, mock_get, mock_magic):
mock_get.assert_has_calls([
mock.call("a"),
mock.call("b"),
], any_order=True)
mock_get.assert_has_calls([
mock.call()(context),
mock.call()(context),
mock.call()(context)
])
], any_order=True)

@mock.patch("rally.benchmark.context.base.Context.get_by_name")
def test_validate(self, mock_get):
Expand All @@ -144,12 +146,11 @@ def test_validate(self, mock_get):
}

base.ContextManager.validate(config)
mock_get.assert_has_calls([
mock.call("ctx1"),
mock.call().validate(config["ctx1"], non_hidden=False),
mock.call("ctx2"),
mock.call().validate(config["ctx2"], non_hidden=False)
])
for ctx in ("ctx1", "ctx2"):
mock_get.assert_has_calls([
mock.call(ctx),
mock.call().validate(config[ctx], non_hidden=False),
])

@mock.patch("rally.benchmark.context.base.Context.get_by_name")
def test_validate_semantic(self, mock_get):
Expand All @@ -159,14 +160,12 @@ def test_validate_semantic(self, mock_get):
}

base.ContextManager.validate_semantic(config)
mock_get.assert_has_calls([
mock.call("ctx1"),
mock.call().validate_semantic(config["ctx1"], admin=None,
users=None, task=None),
mock.call("ctx2"),
mock.call().validate_semantic(config["ctx2"], admin=None,
users=None, task=None)
])
for ctx in ("ctx1", "ctx2"):
mock_get.assert_has_calls([
mock.call(ctx),
mock.call().validate_semantic(config[ctx], admin=None,
users=None, task=None),
])

@mock.patch("rally.benchmark.context.base.Context.get_by_name")
def test_validate_non_hidden(self, mock_get):
Expand All @@ -176,12 +175,11 @@ def test_validate_non_hidden(self, mock_get):
}

base.ContextManager.validate(config, non_hidden=True)
mock_get.assert_has_calls([
mock.call("ctx1"),
mock.call().validate(config["ctx1"], non_hidden=True),
mock.call("ctx2"),
mock.call().validate(config["ctx2"], non_hidden=True)
])
for ctx in ("ctx1", "ctx2"):
mock_get.assert_has_calls([
mock.call(ctx),
mock.call().validate(config[ctx], non_hidden=True),
])

def test_validate__non_existing_context(self):
config = {
Expand Down
17 changes: 6 additions & 11 deletions tests/benchmark/context/test_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@

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.remove_user_role = mock.MagicMock()

self.assertEqual(0, len(fc.keystone().roles.list()))
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())
fc.keystone().roles.create("r1", "test_role1")
fc.keystone().roles.create("r2", "test_role2")
self.assertEqual(2, len(fc.keystone().roles.list()))

@property
Expand All @@ -52,7 +47,7 @@ def context(self):
def test_add_role(self, mock_osclients):
fc = fakes.FakeClients()
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.context["users"] = [{"id": "u1", "tenant_id": "t1"},
Expand All @@ -67,7 +62,7 @@ def test_add_role(self, mock_osclients):
def test_add_role_which_does_not_exist(self, mock_osclients):
fc = fakes.FakeClients()
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.context["users"] = [{"id": "u1", "tenant_id": "t1"},
Expand Down Expand Up @@ -96,7 +91,7 @@ def test_remove_role(self, mock_osclients):
def test_setup_and_cleanup(self, mock_osclients):
fc = fakes.FakeClients()
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:
ctx.context["users"] = [{"id": "u1", "tenant_id": "t1"},
Expand Down
8 changes: 5 additions & 3 deletions tests/benchmark/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ def test__validate_config_syntax(self, mock_context, mock_runner):
config = {"sca": [{"context": "a"}], "scb": [{"runner": "b"}]}
eng = engine.BenchmarkEngine(mock.MagicMock(), mock.MagicMock())
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.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_ctx.ContextManager.validate")
Expand Down Expand Up @@ -218,7 +220,7 @@ def test__validate_config_semantic(self, mock_helper, mock_userctx,
mock.call(admin, user, "a", 1, fake_task, config["a"][1]),
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")
def test_run__update_status(self, mock_consume):
Expand Down

0 comments on commit de68be5

Please sign in to comment.