Skip to content

Commit

Permalink
Use fixed environment for TestAlertRenderTemplate
Browse files Browse the repository at this point in the history
Other tests and local settings sometimes caused this test to fail.
  • Loading branch information
eradman committed Dec 24, 2024
1 parent 89d7f54 commit f67b723
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tests/models/test_alerts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import textwrap
from unittest import TestCase

from redash import settings
from redash.models import OPERATORS, Alert, db, next_state
from tests import BaseTestCase

Expand Down Expand Up @@ -153,6 +154,10 @@ def create_alert(self, results, column="foo", value="5"):
return alert

def test_render_custom_alert_template(self):
old_host = settings.HOST
old_multi_org = settings.MULTI_ORG
settings.HOST = "http://localhost:5001"
settings.MULTI_ORG = False
alert = self.create_alert(get_results(1))
custom_alert = """
<pre>
Expand All @@ -176,9 +181,9 @@ def test_render_custom_alert_template(self):
ALERT_CONDITION equals
ALERT_THRESHOLD 5
ALERT_NAME %s
ALERT_URL https:///default/alerts/%d
ALERT_URL http://localhost:5001/alerts/%d
QUERY_NAME Query
QUERY_URL https:///default/queries/%d
QUERY_URL http://localhost:5001/queries/%d
QUERY_RESULT_VALUE 1
QUERY_RESULT_ROWS [{'foo': 1}]
QUERY_RESULT_COLS [{'name': 'foo', 'type': 'STRING'}]
Expand All @@ -190,6 +195,8 @@ def test_render_custom_alert_template(self):
)
result = alert.render_template(textwrap.dedent(custom_alert))
self.assertMultiLineEqual(result, textwrap.dedent(expected))
settings.HOST = old_host
settings.MULTI_ORG = old_multi_org

def test_render_custom_alert_template_query_table(self):
alert = self.create_alert(get_results(1))
Expand Down

0 comments on commit f67b723

Please sign in to comment.