Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_template(self):
fake_env = Mock()
export = BaseExport(template_env=fake_env)
export.get_template('foo/bar.tpl')
fake_env.get_template.assert_called_with('foo/bar.tpl')
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from mock import Mock
from mock import patch
import pytest
from honcho.export.base import BaseExport
from honcho.export.base import dashrepl
from honcho.export.base import percentescape
class GiraffeExport(BaseExport):
def get_template_loader(self):
return 'longneck'
class TestBaseExport():
@patch('jinja2.Environment')
def test_env_default(self, env_mock):
GiraffeExport()
env_mock.assert_called_with(loader='longneck')
@patch('jinja2.Environment')
@patch('jinja2.FileSystemLoader')
def test_env_template_dir(self, loader_mock, env_mock):
BaseExport(template_dir='foo/bar')
loader_mock.assert_called_with(['foo/bar'])
env_mock.assert_called_with(loader=loader_mock.return_value)
def test_env_template_dir(self, loader_mock, env_mock):
BaseExport(template_dir='foo/bar')
loader_mock.assert_called_with(['foo/bar'])
env_mock.assert_called_with(loader=loader_mock.return_value)
from itertools import groupby
import jinja2
from honcho.export.base import BaseExport
from honcho.export.base import File
from honcho.export.base import dashrepl
class Export(BaseExport):
def get_template_loader(self):
return jinja2.PackageLoader(__name__, 'templates/upstart')
def render(self, processes, context):
master_tpl = self.get_template('master.conf')
process_master_tpl = self.get_template('process_master.conf')
process_tpl = self.get_template('process.conf')
groups = groupby(processes, lambda p: p.name.split('.')[0])
master = "{0}.conf".format(context['app'])
yield File(master, master_tpl.render(context))
for name, procs in groups:
group_name = "{0}-{1}".format(context['app'], name)
import jinja2
from honcho.export.base import BaseExport
from honcho.export.base import File
class Export(BaseExport):
def get_template_loader(self):
return jinja2.PackageLoader(__name__, 'templates/supervisord')
def render(self, processes, context):
context['processes'] = processes
filename = "{0}.conf".format(context['app'])
template = self.get_template('supervisord.conf')
return [File(filename, template.render(context))]