Get the static items tested.

This commit is contained in:
Jeff Baskin 2017-01-18 19:11:23 -05:00
parent 0d7d8dda08
commit 096e830281
4 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,7 @@
{% macro keepalived_config(data) %}
{% if data is none %}
{% else %}
{{ data }}
{% endif %}
{% endmacro %}

View File

@ -0,0 +1,2 @@
{% import 'config.jinja' as config %}
{{ config.keepalived_config(testdata) }}

0
test/__init__.py Normal file
View File

41
test/test_keepalived_config.py Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/python
import os, unittest
from jinja2 import Environment, FileSystemLoader
class TestKeepalivedConfiguration(unittest.TestCase):
def setUp(self):
self.t_dir = os.path.abspath(os.path.join(
os.path.dirname(__file__),
os.pardir,
'keepalived',
'templates'))
self.t_conf = Environment(loader=FileSystemLoader(self.t_dir),
trim_blocks=True)
def _render(self, data):
holder = self.t_conf.get_template('test_config.jinja').render(testdata=data)
print(repr(holder))
return holder
def test_string(self):
testdata = 'stuff'
result = 'stuff\n'
self.assertEqual(self._render(testdata), result,
'A string should be returned with a line feed.')
def test_number(self):
testdata = 3
result = '3\n'
self.assertEqual(self._render(testdata), result,
'A number should be returned with a line feed.')
def test_null(self):
testdata = None
result = '\n'
self.assertEqual(self._render(testdata), result,
'A null should just return a line feed.')
if __name__ == '__main__':
unittest.main()