Files
zaza-openstack-tests/unit_tests/test_zaza_charm_lifecycle_utils.py
T
David Ames 33b74f2da8 Use yaml.safe_load
We should be using yaml.safe_load and not yaml.load in all of our code.
2018-11-29 09:26:21 -08:00

53 lines
1.9 KiB
Python

# Copyright 2018 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
import zaza.charm_lifecycle.utils as lc_utils
import unit_tests.utils as ut_utils
class TestCharmLifecycleUtils(ut_utils.BaseTestCase):
def test_generate_model_name(self):
self.patch_object(lc_utils.uuid, "uuid4")
self.uuid4.return_value = "longer-than-12characters"
self.assertEqual(lc_utils.generate_model_name(),
"zaza-12characters")
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.safe_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.safe_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))