Fixing failure report rendering (#5492)

This commit is contained in:
adamzwakk
2021-05-14 09:25:52 -04:00
committed by GitHub
parent 8e728308ab
commit e4e567bbb9
2 changed files with 15 additions and 1 deletions

View File

@@ -211,7 +211,7 @@ def render_template(path, context):
Using Flask's `render_template` function requires the entire app context to load, which in turn triggers any
function decorated with the `context_processor` decorator, which is not explicitly required for rendering purposes.
"""
current_app.jinja_env.get_template(path).render(**context)
return current_app.jinja_env.get_template(path).render(**context)
def query_is_select_no_limit(query):

View File

@@ -1,12 +1,14 @@
from collections import namedtuple
from unittest import TestCase
from redash import create_app
from redash.utils import (
build_url,
collect_parameters_from_request,
filter_none,
json_dumps,
generate_token,
render_template,
)
@@ -78,3 +80,15 @@ class TestGenerateToken(TestCase):
def test_format(self):
token = generate_token(40)
self.assertRegex(token, r"[a-zA-Z0-9]{40}")
class TestRenderTemplate(TestCase):
def test_render(self):
app = create_app()
with app.app_context():
d = {"failures": [{"id": 1, "name": "Failure Unit Test", "failed_at": "May 04, 2021 02:07PM UTC", "failure_reason": "", "failure_count": 1, "comment": None}]}
html, text = [
render_template("emails/failures.{}".format(f), d)
for f in ["html", "txt"]
]
self.assertIn('Failure Unit Test',html)
self.assertIn('Failure Unit Test',text)