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
This commit is contained in:
parent
59865a1be9
commit
895ce942c3
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user