def test_render_template(self): self.patch_object(lc_deploy, 'get_template_overlay_context') template_mock = mock.MagicMock() template_mock.render.return_value = 'Template contents' m = mock.mock_open() with mock.patch('zaza.charm_lifecycle.deploy.open', m, create=True): lc_deploy.render_template(template_mock, '/tmp/mybundle.yaml') m.assert_called_once_with('/tmp/mybundle.yaml', 'w') handle = m() handle.write.assert_called_once_with('Template contents')
def test_template_missing_required_variables(self): self.patch_object(lc_deploy, 'get_template_overlay_context') self.get_template_overlay_context.return_value = {} self.patch_object(lc_deploy.sys, 'exit') self.patch_object(lc_deploy.logging, 'error') jinja2_env = lc_deploy.get_jinja2_env() template = jinja2_env.from_string('{{required_variable}}') m = mock.mock_open() with mock.patch('zaza.charm_lifecycle.deploy.open', m, create=True): lc_deploy.render_template(template, '/tmp/mybundle.yaml') m.assert_called_once_with('/tmp/mybundle.yaml', 'w') self.error.assert_called_once_with( "Template error. You may be missing" " a mandatory environment variable : " "'required_variable' is undefined") self.exit.assert_called_once_with(1)