Files
zaza-openstack-tests/unit_tests/test_zaza_charm_lifecycle_utils.py
T
Liam Young 9d06bb890f Move call to get_juju_model() down to run_in_model
Currently interacting with functions in zaza.model requires the
model to be passed in. This has resulted in multiple calls to
get_juju_model(). It is cleaner to push these calls down into
the model wrapper and make the model_name an optional
argument. In addition, the current model name is now cached
without having to check the os.env each time.

Unfortunately this has resulted in the signature changing on a
great many function so this diff is bigger than would normally
be desirable.
2018-06-14 06:19:26 +01:00

33 lines
1.1 KiB
Python

import mock
import zaza.charm_lifecycle.utils as lc_utils
import unit_tests.utils as ut_utils
class TestCharmLifecycleUtils(ut_utils.BaseTestCase):
def test_get_charm_config(self):
self.patch("builtins.open",
new_callable=mock.mock_open(),
name="_open")
self.patch_object(lc_utils, 'yaml')
_yaml = "testconfig: someconfig"
_yaml_dict = {'test_config': 'someconfig'}
self.yaml.load.return_value = _yaml_dict
_filename = "filename"
_fileobj = mock.MagicMock()
_fileobj.__enter__.return_value = _yaml
self._open.return_value = _fileobj
self.assertEqual(lc_utils.get_charm_config(yaml_file=_filename),
_yaml_dict)
self._open.assert_called_once_with(_filename, "r")
self.yaml.load.assert_called_once_with(_yaml)
def test_get_class(self):
self.assertEqual(
type(lc_utils.get_class('unit_tests.'
'test_zaza_charm_lifecycle_utils.'
'TestCharmLifecycleUtils')()),
type(self))