Skip to content

Commit c685414

Browse files
author
Kosma Grochowski
committed
Fix issues according to code review
1 parent 72ecc2b commit c685414

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

dbt_airflow_factory/notifications/handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ def failure_handler(context: Any) -> None:
8787
logs_url = f"{webserver_url}/{query}"
8888

8989
message_text = handler_definition["message_template"].format(
90-
task_id=task_id,
91-
dag_id=dag_id,
92-
execution_date=context.get("execution_date"),
93-
log_url=logs_url,
90+
task=task_id,
91+
dag=dag_id,
92+
execution_time=context.get("execution_date"),
93+
url=logs_url,
9494
)
9595
message_body = {"text": message_text}
9696

tests/config/notifications_google_chat/airflow.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ failure_handlers:
55
connection_id: google_chat_failure
66
message_template: |
77
🔴 *Task Failed*
8-
*Task*: {task_id}
9-
*Dag*: {dag_id}
10-
*Execution Time*: {execution_date}
11-
*Log Url*: {log_url}
8+
*Task*: {task}
9+
*Dag*: {dag}
10+
*Execution Time*: {execution_time}
11+
*Log Url*: {url}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
🔴*TaskFailed*
2+
*Task*:task_id
3+
*Dag*:dag_id
4+
*ExecutionTime*:somedate
5+
*LogUrl*:https://your.airflow-webserver.url/log?dag_id=dag_id&task_id=task_id&execution_date=ts

tests/test_notifications.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ def create_context():
150150
if IS_AIRFLOW_NEWER_THAN_2_4
151151
else "airflow.hooks.base_hook.BaseHook.get_connection"
152152
)
153-
@patch("dbt_airflow_factory.notifications.handler.HttpHook")
154-
def test_notification_send_for_google_chat(mock_http_hook, mock_get_connection):
153+
@patch("dbt_airflow_factory.notifications.handler.HttpHook.run")
154+
def test_notification_send_for_google_chat(mock_run, mock_get_connection):
155155
# given
156156
notifications_config = AirflowDagFactory(
157157
path.dirname(path.abspath(__file__)), "notifications_google_chat"
@@ -163,4 +163,10 @@ def test_notification_send_for_google_chat(mock_http_hook, mock_get_connection):
163163
factory.create_failure_handler(notifications_config)(context)
164164

165165
# then
166-
mock_http_hook.assert_called_once()
166+
request = mock_run.call_args_list[0].kwargs
167+
mock_run.assert_called_once()
168+
169+
actual_request_data = json.loads(request["data"].replace("\n", "").replace(" ", ""))
170+
expected_request_data_path = pathlib.Path(__file__).parent / "google_chat_expected_data.txt"
171+
expected_request_data_text = pathlib.Path(expected_request_data_path).read_text()
172+
assert actual_request_data['text'] == expected_request_data_text

0 commit comments

Comments
 (0)