Mock Zun fake client method

* The Zun client doesn't have an rpm packaging so
running the unit test might fail if not installed.

* The Designate client was fixed so there is no need to mock it.

* Use Mock Fixture instead of calling directly the mock.patch,object

Change-Id: Id7226c889c18dbe3a38b106b0cdac5e331f54e3a
This commit is contained in:
Eyal 2020-02-10 10:06:50 +02:00
parent 91ff80c79d
commit b8943be736
2 changed files with 12 additions and 19 deletions

View File

@ -711,10 +711,9 @@ class DesignateAction(base.OpenStackAction):
@classmethod
def _get_fake_client(cls):
session = keystone_utils.get_admin_session()
return cls._get_client_class()(
endpoint_override="http://127.0.0.1:9001/",
session=session
session=ks_session.Session()
)

View File

@ -13,10 +13,9 @@
import contextlib
import os
import fixtures
from oslo_config import cfg
import mock
from mistral_extra.actions import generator_factory
from mistral_extra.actions.openstack.action_generator import base as \
generator_base
@ -78,22 +77,17 @@ class GeneratorTest(base.BaseTest):
# when it is initialised and attempts to connect. This mocks out this
# service only and returns a simple function that can be used by the
# inspection utils.
self.baremetal_patch = mock.patch.object(
actions.BaremetalIntrospectionAction,
"get_fake_client_method",
return_value=lambda x: None)
self.useFixture(fixtures.MockPatchObject(
actions.BaremetalIntrospectionAction, "get_fake_client_method",
return_value=lambda x: None))
self.baremetal_patch.start()
self.addCleanup(self.baremetal_patch.stop)
# Do the same for the Designate client.
self.designate_patch = mock.patch.object(
actions.DesignateAction,
"get_fake_client_method",
return_value=lambda x: None)
self.designate_patch.start()
self.addCleanup(self.designate_patch.stop)
# Do the same for the Zun client.
# There is no rpm packaging for Zun client
# so importing the client will fail when building
# the rpm and running the unittest so lets mock it
self.useFixture(fixtures.MockPatchObject(
actions.ZunAction, "get_fake_client_method",
return_value=lambda x: None))
def test_generator(self):
for generator_cls in generator_factory.all_generators():