From 895ce942c3d443e1a224cad959d9a8c7bd644ad7 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 4 Jun 2015 10:38:39 -0500 Subject: [PATCH] Authenticate scenario unit test improvements This makes several improvements to the unit tests for the Authenticate scenario: * Unit tests were in two files; one test was duplicated. They are combined into a single file that is the same predictable place as the other scenario unit tests. * Mocking of the Scenario.clients function is made consistent with the other scenario unit tests. * Other misc. cleanup. Change-Id: Iaa86ef514534ada00e868be564f0b6acd6b11ff1 --- .../authenticate/test_authenticate.py | 64 ++++++++++++++++--- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/tests/unit/plugins/openstack/scenarios/authenticate/test_authenticate.py b/tests/unit/plugins/openstack/scenarios/authenticate/test_authenticate.py index 4e99e376..01b88fd9 100644 --- a/tests/unit/plugins/openstack/scenarios/authenticate/test_authenticate.py +++ b/tests/unit/plugins/openstack/scenarios/authenticate/test_authenticate.py @@ -15,20 +15,64 @@ import mock +from rally.benchmark.scenarios import base from rally.plugins.openstack.scenarios.authenticate import authenticate -from tests.unit import fakes from tests.unit import test +AUTHENTICATE_MODULE = ( + "rally.plugins.openstack.scenarios.authenticate.authenticate") + + class AuthenticateTestCase(test.TestCase): - @mock.patch("rally.osclients") - def test_keystone(self, mock_osclients): - fc = fakes.FakeClients() - mock_osclients.Clients.return_value = fc - - scenario = authenticate.Authenticate(admin_clients=mock_osclients, - clients=mock_osclients) - + @mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients") + def test_keystone(self, mock_clients): + scenario = authenticate.Authenticate() scenario.keystone() - self.assertEqual(scenario._clients.keystone.call_count, 1) + mock_clients.assert_called_once_with("keystone") + + @mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients") + def test_validate_glance(self, mock_clients): + scenario = authenticate.Authenticate() + mock_clients.return_value.images.list = mock.MagicMock() + image_name = "__intentionally_non_existent_image___" + with base.AtomicAction(scenario, "authenticate.validate_glance"): + scenario.validate_glance(5) + mock_clients.return_value.images.list.assert_called_with( + name=image_name) + self.assertEqual(mock_clients.return_value.images.list.call_count, 5) + + @mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients") + def test_validate_nova(self, mock_clients): + scenario = authenticate.Authenticate() + mock_clients.return_value.flavors.list = mock.MagicMock() + with base.AtomicAction(scenario, "authenticate.validate_nova"): + scenario.validate_nova(5) + self.assertEqual(mock_clients.return_value.flavors.list.call_count, 5) + + @mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients") + def test_validate_cinder(self, mock_clients): + scenario = authenticate.Authenticate() + mock_clients.return_value.volume_types.list = mock.MagicMock() + with base.AtomicAction(scenario, "authenticate.validate_cinder"): + scenario.validate_cinder(5) + self.assertEqual(mock_clients.return_value.volume_types. + list.call_count, 5) + + @mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients") + def test_validate_neutron(self, mock_clients): + scenario = authenticate.Authenticate() + mock_clients.return_value.get_auth_info = mock.MagicMock() + with base.AtomicAction(scenario, "authenticate.validate_neutron"): + scenario.validate_neutron(5) + self.assertEqual(mock_clients.return_value.get_auth_info.call_count, 5) + + @mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients") + def test_validate_heat(self, mock_clients): + scenario = authenticate.Authenticate() + mock_clients.return_value.stacks.list = mock.MagicMock() + with base.AtomicAction(scenario, "authenticate.validate_heat"): + scenario.validate_heat(5) + mock_clients.return_value.stacks.list.assert_called_with(limit=0) + self.assertEqual(mock_clients.return_value.stacks.list.call_count, 5)