Use charms.openstack charmhelpers test_mocks
Every reactive charm that uses charms.openstack and implements unit testing needs to mock charmhelpers, as otherwise the tests blow up. This patch uses the mocking of charmhelpers in charms.openstack so that a charm layer can just import test_mocks and charmhelpers will be mocked out along with setting up a default charmhelpers.c.o.u.OPENSTACK_RELEASES so that when an OpenStackCharm() derived charm class won't fail on definition. Change-Id: I489b15301f64310f7077d0e7246fd5e116877ed9 Related-Bug: #1693017 Depends-On: I5ac40617ee30e5f421ec16fc7592177a5e6aa166
This commit is contained in:
parent
b57040e12a
commit
355fc831b7
|
@ -0,0 +1,7 @@
|
|||
build
|
||||
layers
|
||||
.tox
|
||||
interfaces
|
||||
.testrepository
|
||||
*__pycache__*
|
||||
*.pyc
|
|
@ -0,0 +1,4 @@
|
|||
[gerrit]
|
||||
host=review.openstack.org
|
||||
port=29418
|
||||
project=openstack/charm-murano.git
|
|
@ -46,7 +46,7 @@ class MuranoCharm(charms_openstack.charm.HAOpenStackCharm):
|
|||
"""
|
||||
if release is None:
|
||||
release = ch_utils.os_release('python-keystonemiddleware')
|
||||
super(MuranoCharm, self).__init__(release=release, **kwargs)
|
||||
super().__init__(release=release, **kwargs)
|
||||
|
||||
def get_amqp_credentials(self):
|
||||
"""Provide the default amqp username and vhost as a tuple.
|
||||
|
|
|
@ -13,34 +13,10 @@
|
|||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
import mock
|
||||
|
||||
sys.path.append('src')
|
||||
sys.path.append('src/lib')
|
||||
|
||||
# Mock out charmhelpers so that we can test without it.
|
||||
# also stops sideeffects from occuring.
|
||||
charmhelpers = mock.MagicMock()
|
||||
apt_pkg = mock.MagicMock()
|
||||
sys.modules['apt_pkg'] = apt_pkg
|
||||
sys.modules['charmhelpers'] = charmhelpers
|
||||
sys.modules['charmhelpers.core'] = charmhelpers.core
|
||||
sys.modules['charmhelpers.core.decorators'] = charmhelpers.core.decorators
|
||||
sys.modules['charmhelpers.core.hookenv'] = charmhelpers.core.hookenv
|
||||
sys.modules['charmhelpers.core.host'] = charmhelpers.core.host
|
||||
sys.modules['charmhelpers.core.unitdata'] = charmhelpers.core.unitdata
|
||||
sys.modules['charmhelpers.core.templating'] = charmhelpers.core.templating
|
||||
sys.modules['charmhelpers.contrib'] = charmhelpers.contrib
|
||||
sys.modules['charmhelpers.contrib.openstack'] = charmhelpers.contrib.openstack
|
||||
sys.modules['charmhelpers.contrib.openstack.utils'] = (
|
||||
charmhelpers.contrib.openstack.utils)
|
||||
sys.modules['charmhelpers.contrib.openstack.templating'] = (
|
||||
charmhelpers.contrib.openstack.templating)
|
||||
sys.modules['charmhelpers.contrib.network'] = charmhelpers.contrib.network
|
||||
sys.modules['charmhelpers.contrib.network.ip'] = (
|
||||
charmhelpers.contrib.network.ip)
|
||||
sys.modules['charmhelpers.fetch'] = charmhelpers.fetch
|
||||
sys.modules['charmhelpers.cli'] = charmhelpers.cli
|
||||
sys.modules['charmhelpers.contrib.hahelpers'] = charmhelpers.contrib.hahelpers
|
||||
sys.modules['charmhelpers.contrib.hahelpers.cluster'] = (
|
||||
charmhelpers.contrib.hahelpers.cluster)
|
||||
import charms_openstack.test_mocks # noqa
|
||||
charms_openstack.test_mocks.mock_charmhelpers()
|
||||
|
|
|
@ -72,15 +72,7 @@ class Helper(unittest.TestCase):
|
|||
|
||||
class TestMuranoCharm(Helper):
|
||||
|
||||
def test_install(self):
|
||||
self.patch(murano.MuranoCharm, 'configure_source')
|
||||
a = murano.MuranoCharm(release='mitaka')
|
||||
a.install()
|
||||
self.configure_source.assert_called_with()
|
||||
|
||||
def test__init__(self):
|
||||
self.patch(murano.MuranoCharm,
|
||||
'set_config_defined_certs_and_keys')
|
||||
self.patch(murano.ch_utils, 'os_release')
|
||||
murano.MuranoCharm()
|
||||
self.os_release.assert_called_once_with('python-keystonemiddleware')
|
||||
|
|
Loading…
Reference in New Issue