Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing failure report rendering #5492

Merged
merged 3 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion redash/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand Down Expand Up @@ -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)