This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 7857ca2d20 feat: make `cc` and `bcc` templated fields in EmailOperator 
(#35235)
7857ca2d20 is described below

commit 7857ca2d203f4a672fc618c41027d7f4b67d4320
Author: Joffrey Bienvenu <[email protected]>
AuthorDate: Sat Oct 28 17:35:16 2023 +0200

    feat: make `cc` and `bcc` templated fields in EmailOperator (#35235)
---
 airflow/providers/smtp/operators/smtp.py    |  6 +++---
 tests/providers/smtp/operators/test_smtp.py | 11 ++++++++++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/airflow/providers/smtp/operators/smtp.py 
b/airflow/providers/smtp/operators/smtp.py
index 8dd6889ab0..db1f162c21 100644
--- a/airflow/providers/smtp/operators/smtp.py
+++ b/airflow/providers/smtp/operators/smtp.py
@@ -36,15 +36,15 @@ class EmailOperator(BaseOperator):
     :param html_content: content of the email, html markup
         is allowed. (templated)
     :param files: file names to attach in email (templated)
-    :param cc: list of recipients to be added in CC field
-    :param bcc: list of recipients to be added in BCC field
+    :param cc: list of recipients to be added in CC field (templated)
+    :param bcc: list of recipients to be added in BCC field (templated)
     :param mime_subtype: MIME sub content type
     :param mime_charset: character set parameter added to the Content-Type
         header.
     :param custom_headers: additional headers to add to the MIME message.
     """
 
-    template_fields: Sequence[str] = ("to", "from_email", "subject", 
"html_content", "files")
+    template_fields: Sequence[str] = ("to", "from_email", "subject", 
"html_content", "files", "cc", "bcc")
     template_fields_renderers = {"html_content": "html"}
     template_ext: Sequence[str] = (".html",)
     ui_color = "#e6faf9"
diff --git a/tests/providers/smtp/operators/test_smtp.py 
b/tests/providers/smtp/operators/test_smtp.py
index 0786d0b073..6239c058da 100644
--- a/tests/providers/smtp/operators/test_smtp.py
+++ b/tests/providers/smtp/operators/test_smtp.py
@@ -27,6 +27,9 @@ smtplib_string = "airflow.providers.smtp.hooks.smtp.smtplib"
 
 
 class TestEmailOperator:
+    def setup_method(self):
+        self.default_op_kwargs = dict(to="to", subject="subject", 
html_content="content")
+
     @patch("airflow.providers.smtp.hooks.smtp.SmtpHook.get_connection")
     @patch(smtplib_string)
     def test_loading_sender_email_from_connection(self, mock_smtplib, 
mock_hook_conn):
@@ -46,7 +49,13 @@ class TestEmailOperator:
             ),
         )
         smtp_client_mock = mock_smtplib.SMTP_SSL()
-        op = EmailOperator(task_id="test_email", to="to", subject="subject", 
html_content="content")
+        op = EmailOperator(task_id="test_email", **self.default_op_kwargs)
         op.execute({})
         call_args = smtp_client_mock.sendmail.call_args.kwargs
         assert call_args["from_addr"] == sender_email
+
+    def test_assert_templated_fields(self):
+        """Test expected templated fields."""
+        operator = EmailOperator(task_id="test_assert_templated_fields", 
**self.default_op_kwargs)
+        template_fields = ("to", "from_email", "subject", "html_content", 
"files", "cc", "bcc")
+        assert operator.template_fields == template_fields

Reply via email to