unit test templater
This commit is contained in:
parent
b72d495cec
commit
8b38769cfc
2 changed files with 34 additions and 1 deletions
|
@ -5,12 +5,25 @@ import os
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
from stacosys.conf import config
|
|
||||||
|
|
||||||
current_path = os.path.dirname(__file__)
|
current_path = os.path.dirname(__file__)
|
||||||
template_path = os.path.abspath(os.path.join(current_path, "../templates"))
|
template_path = os.path.abspath(os.path.join(current_path, "../templates"))
|
||||||
env = Environment(loader=FileSystemLoader(template_path))
|
env = Environment(loader=FileSystemLoader(template_path))
|
||||||
|
|
||||||
|
TEMPLATE_DROP_COMMENT = "drop_comment"
|
||||||
|
TEMPLATE_APPROVE_COMMENT = "approve_comment"
|
||||||
|
TEMPLATE_NEW_COMMENT = "new_comment"
|
||||||
|
|
||||||
def get_template(lang, name):
|
def get_template(lang, name):
|
||||||
return env.get_template(lang + "/" + name + ".tpl")
|
return env.get_template(lang + "/" + name + ".tpl")
|
||||||
|
|
||||||
|
class Templater:
|
||||||
|
|
||||||
|
def __init__(self, lang, template_path):
|
||||||
|
self._env = Environment(loader=FileSystemLoader(template_path))
|
||||||
|
self._lang = lang
|
||||||
|
|
||||||
|
def get_template(self, name):
|
||||||
|
return self._env.get_template(self._lang + "/" + name + ".tpl")
|
||||||
|
|
||||||
|
|
||||||
|
|
20
tests/test_templater.py
Normal file
20
tests/test_templater.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from stacosys.core.templater import Templater, TEMPLATE_APPROVE_COMMENT
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def templater_fr():
|
||||||
|
current_path = os.path.dirname(__file__)
|
||||||
|
template_path = os.path.abspath(os.path.join(current_path, "../stacosys/templates"))
|
||||||
|
return Templater("fr", template_path)
|
||||||
|
|
||||||
|
def test_approve_comment_fr(templater_fr):
|
||||||
|
template = templater_fr.get_template(TEMPLATE_APPROVE_COMMENT)
|
||||||
|
assert template
|
||||||
|
content = template.render(original="texte original")
|
||||||
|
assert content.startswith("Bonjour,\n\nLe commentaire sera bientôt publié.")
|
||||||
|
assert content.endswith("texte original")
|
Loading…
Add table
Reference in a new issue