diff --git a/shade/tests/fakes.py b/shade/tests/fakes.py index fa6a75b9c..fadf5c1e0 100644 --- a/shade/tests/fakes.py +++ b/shade/tests/fakes.py @@ -193,3 +193,9 @@ class FakeGroup(object): self.name = name self.description = description self.domain = domain + + +class FakeHypervisor(object): + def __init__(self, id, hostname): + self.id = id + self.hypervisor_hostname = hostname diff --git a/shade/tests/unit/test_shade_operator.py b/shade/tests/unit/test_shade_operator.py index a7fe3ee9d..c5e9774aa 100644 --- a/shade/tests/unit/test_shade_operator.py +++ b/shade/tests/unit/test_shade_operator.py @@ -19,7 +19,6 @@ import testtools from os_client_config import cloud_config import shade -import munch from shade import exc from shade import meta from shade.tests import fakes @@ -1054,17 +1053,17 @@ class TestShadeOperator(base.TestCase): get_session_mock.return_value = session_mock self.assertTrue(self.cloud.has_service("image")) - @mock.patch.object(shade._tasks.HypervisorList, 'main') - def test_list_hypervisors(self, mock_hypervisorlist): + @mock.patch.object(shade.OpenStackCloud, 'nova_client') + def test_list_hypervisors(self, mock_nova): '''This test verifies that calling list_hypervisors results in a call - to the HypervisorList task.''' - mock_hypervisorlist.return_value = [ - munch.Munch({'hypervisor_hostname': 'testserver1', - 'id': '1'}), - munch.Munch({'hypervisor_hostname': 'testserver2', - 'id': '2'}) + to nova client.''' + mock_nova.hypervisors.list.return_value = [ + fakes.FakeHypervisor('1', 'testserver1'), + fakes.FakeHypervisor('2', 'testserver2'), ] r = self.cloud.list_hypervisors() + mock_nova.hypervisors.list.assert_called_once_with() self.assertEquals(2, len(r)) self.assertEquals('testserver1', r[0]['hypervisor_hostname']) + self.assertEquals('testserver2', r[1]['hypervisor_hostname'])