forked from apache/airflow
-
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.
Deprecate smtp configs in airflow settings / local_settings (apache#3…
…7711) * Deprecate smtp configs in airflow settings / local_settings * Add header to jinja2 template * Update tests and provider version pin
- Loading branch information
1 parent
27b4d06
commit 5b31b63
Showing
5 changed files
with
99 additions
and
35 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
23 changes: 23 additions & 0 deletions
23
airflow/providers/smtp/notifications/templates/email_subject.jinja2
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{# | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
#} | ||
{% if ti is defined %} | ||
DAG {{ ti.dag_id }} - Task {{ ti.task_id }} - Run ID {{ ti.run_id }} in State {{ ti.state }} | ||
{% elif slas is defined %} | ||
SLA Missed for DAG {{ dag.dag_id }} - Task {{ slas[0].task_id }} | ||
{% endif %} |
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
from __future__ import annotations | ||
|
||
import tempfile | ||
from unittest import mock | ||
|
||
import pytest | ||
|
@@ -30,6 +31,7 @@ | |
send_smtp_notification, | ||
) | ||
from airflow.utils import timezone | ||
from tests.test_utils.config import conf_vars | ||
|
||
pytestmark = pytest.mark.db_test | ||
|
||
|
@@ -166,3 +168,42 @@ def test_notifier_with_defaults_sla(self, mock_smtphook_hook, dag_maker): | |
mime_charset="utf-8", | ||
custom_headers=None, | ||
) | ||
|
||
@mock.patch("airflow.providers.smtp.notifications.smtp.SmtpHook") | ||
def test_notifier_with_nondefault_conf_vars(self, mock_smtphook_hook, create_task_instance): | ||
ti = create_task_instance(dag_id="dag", task_id="op", execution_date=timezone.datetime(2018, 1, 1)) | ||
context = {"dag": ti.dag_run.dag, "ti": ti} | ||
|
||
with tempfile.NamedTemporaryFile(mode="wt", suffix=".txt") as f_subject, tempfile.NamedTemporaryFile( | ||
mode="wt", suffix=".txt" | ||
) as f_content: | ||
f_subject.write("Task {{ ti.task_id }} failed") | ||
f_subject.flush() | ||
|
||
f_content.write("Mock content goes here") | ||
f_content.flush() | ||
|
||
with conf_vars( | ||
{ | ||
("smtp", "templated_html_content_path"): f_content.name, | ||
("smtp", "templated_email_subject_path"): f_subject.name, | ||
} | ||
): | ||
notifier = SmtpNotifier( | ||
from_email=conf.get("smtp", "smtp_mail_from"), | ||
to="[email protected]", | ||
) | ||
notifier(context) | ||
mock_smtphook_hook.return_value.__enter__().send_email_smtp.assert_called_once_with( | ||
from_email=conf.get("smtp", "smtp_mail_from"), | ||
to="[email protected]", | ||
subject="Task op failed", | ||
html_content="Mock content goes here", | ||
smtp_conn_id="smtp_default", | ||
files=None, | ||
cc=None, | ||
bcc=None, | ||
mime_subtype="mixed", | ||
mime_charset="utf-8", | ||
custom_headers=None, | ||
) |