forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add test email functionality to SQL-based email alerts (apache#…
…10476) * added test email functionality * formatting changes * more formatting * applied requested changes * mypy Co-authored-by: Jason Davis <@dropbox.com>
- Loading branch information
Showing
4 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,9 @@ | |
|
||
from superset import db | ||
from superset.models.alerts import Alert, AlertLog | ||
from superset.models.schedules import ScheduleType | ||
from superset.models.slice import Slice | ||
from superset.tasks.schedules import run_alert_query | ||
from superset.tasks.schedules import run_alert_query, schedule_alert_query | ||
from superset.utils import core as utils | ||
from tests.test_app import app | ||
|
||
|
@@ -112,3 +113,31 @@ def test_run_alert_query(mock_error, mock_deliver, setup_database): | |
run_alert_query(database.query(Alert).filter_by(id=5).one(), database) | ||
assert mock_deliver.call_count == 1 | ||
assert mock_error.call_count == 4 | ||
|
||
|
||
@patch("superset.tasks.schedules.deliver_alert") | ||
@patch("superset.tasks.schedules.run_alert_query") | ||
def test_schedule_alert_query(mock_run_alert, mock_deliver_alert, setup_database): | ||
database = setup_database | ||
active_alert = database.query(Alert).filter_by(id=1).one() | ||
inactive_alert = database.query(Alert).filter_by(id=3).one() | ||
|
||
# Test that inactive alerts are no processed | ||
schedule_alert_query(report_type=ScheduleType.alert, schedule_id=inactive_alert.id) | ||
assert mock_run_alert.call_count == 0 | ||
assert mock_deliver_alert.call_count == 0 | ||
|
||
# Test that active alerts with no recipients passed in are processed regularly | ||
schedule_alert_query(report_type=ScheduleType.alert, schedule_id=active_alert.id) | ||
assert mock_run_alert.call_count == 1 | ||
assert mock_deliver_alert.call_count == 0 | ||
|
||
# Test that active alerts sent as a test are delivered immediately | ||
schedule_alert_query( | ||
report_type=ScheduleType.alert, | ||
schedule_id=active_alert.id, | ||
recipients="[email protected]", | ||
is_test_alert=True, | ||
) | ||
assert mock_run_alert.call_count == 1 | ||
assert mock_deliver_alert.call_count == 1 |