From 3355ad9408b6cb8e4cf27c9a89cb8790efe2ad1f Mon Sep 17 00:00:00 2001 From: Kaxil Naik Date: Thu, 27 Jun 2019 20:52:17 +0530 Subject: [PATCH] [AIRFLOW-4857] Add templated fields to SlackWebhookOperator (#5490) (cherry picked from commit 8b7f93d2a2b3cf1f0c091464ad2f3cd26940e66b) --- airflow/contrib/operators/slack_webhook_operator.py | 3 +++ .../contrib/operators/test_slack_webhook_operator.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/airflow/contrib/operators/slack_webhook_operator.py b/airflow/contrib/operators/slack_webhook_operator.py index c9e7ba19af9e9..6a354360b9cf1 100644 --- a/airflow/contrib/operators/slack_webhook_operator.py +++ b/airflow/contrib/operators/slack_webhook_operator.py @@ -54,6 +54,9 @@ class SlackWebhookOperator(SimpleHttpOperator): :type proxy: str """ + template_fields = ['webhook_token', 'message', 'attachments', 'channel', + 'username', 'proxy', ] + @apply_defaults def __init__(self, http_conn_id=None, diff --git a/tests/contrib/operators/test_slack_webhook_operator.py b/tests/contrib/operators/test_slack_webhook_operator.py index 68078bb8018a9..ed05af76164b2 100644 --- a/tests/contrib/operators/test_slack_webhook_operator.py +++ b/tests/contrib/operators/test_slack_webhook_operator.py @@ -67,6 +67,17 @@ def test_execute(self): self.assertEqual(self._config['link_names'], operator.link_names) self.assertEqual(self._config['proxy'], operator.proxy) + def test_assert_templated_fields(self): + operator = SlackWebhookOperator( + task_id='slack_webhook_job', + dag=self.dag, + **self._config + ) + + template_fields = ['webhook_token', 'message', 'attachments', 'channel', 'username', 'proxy'] + + self.assertEqual(operator.template_fields, template_fields) + if __name__ == '__main__': unittest.main()