From b8943be7361e8db6681255a9fa62b3aa30dcd120 Mon Sep 17 00:00:00 2001 From: Eyal Date: Mon, 10 Feb 2020 10:06:50 +0200 Subject: [PATCH] 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 --- mistral_extra/actions/openstack/actions.py | 3 +- .../unit/actions/openstack/test_generator.py | 28 ++++++++----------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/mistral_extra/actions/openstack/actions.py b/mistral_extra/actions/openstack/actions.py index 9091875..8fe769c 100644 --- a/mistral_extra/actions/openstack/actions.py +++ b/mistral_extra/actions/openstack/actions.py @@ -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() ) diff --git a/mistral_extra/tests/unit/actions/openstack/test_generator.py b/mistral_extra/tests/unit/actions/openstack/test_generator.py index 42c10ae..c68678a 100644 --- a/mistral_extra/tests/unit/actions/openstack/test_generator.py +++ b/mistral_extra/tests/unit/actions/openstack/test_generator.py @@ -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():