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 9b46d76ee4f Remove db dependency for apprise notifier tests (#54578)
9b46d76ee4f is described below
commit 9b46d76ee4fffdbefa7fa14aba5b7d8a8ec15f3b
Author: GPK <[email protected]>
AuthorDate: Sun Aug 17 08:24:03 2025 +0100
Remove db dependency for apprise notifier tests (#54578)
---
.pre-commit-config.yaml | 1 +
.../unit/apprise/notifications/test_apprise.py | 102 +++++++++++----------
2 files changed, 57 insertions(+), 46 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 6476a7c9c25..f4c4d8de334 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -614,6 +614,7 @@ repos:
^providers/apache/flink/.*\.py$|
^providers/apache/iceberg/.*\.py$|
^providers/apache/kafka/.*\.py$|
+ ^providers/apprise/.*\.py$|
^providers/arangodb/.*\.py$|
^providers/asana/.*\.py$|
^providers/cloudant/.*\.py$|
diff --git a/providers/apprise/tests/unit/apprise/notifications/test_apprise.py
b/providers/apprise/tests/unit/apprise/notifications/test_apprise.py
index 2aafde91359..e9aa03f1669 100644
--- a/providers/apprise/tests/unit/apprise/notifications/test_apprise.py
+++ b/providers/apprise/tests/unit/apprise/notifications/test_apprise.py
@@ -22,69 +22,79 @@ from unittest import mock
import pytest
from apprise import NotifyFormat, NotifyType
+from airflow.models import Connection
from airflow.providers.apprise.notifications.apprise import (
AppriseNotifier,
send_apprise_notification,
)
-from airflow.providers.standard.operators.empty import EmptyOperator
-
-pytestmark = pytest.mark.db_test
class TestAppriseNotifier:
+ @pytest.fixture(autouse=True)
+ def setup_connections(self, create_connection_without_db):
+ extra = {"config": {"path": "http://some_path_that_dont_exist/",
"tag": "alert"}}
+ create_connection_without_db(
+ Connection(
+ conn_id="apprise_default",
+ conn_type="apprise",
+ extra=extra,
+ )
+ )
+
@mock.patch("airflow.providers.apprise.notifications.apprise.AppriseHook")
- def test_notifier(self, mock_apprise_hook, dag_maker):
- with dag_maker("test_notifier") as dag:
- EmptyOperator(task_id="task1")
+ def test_notifier(self, mock_apprise_hook, create_dag_without_db):
notifier = send_apprise_notification(body="DISK at 99%",
notify_type=NotifyType.FAILURE)
- notifier({"dag": dag})
- mock_apprise_hook.return_value.notify.assert_called_once_with(
- body="DISK at 99%",
- notify_type=NotifyType.FAILURE,
- title=None,
- body_format=NotifyFormat.TEXT,
- tag="all",
- attach=None,
- interpret_escapes=None,
- config=None,
- )
+ notifier({"dag": create_dag_without_db("test_notifier")})
+ call_args = mock_apprise_hook.return_value.notify.call_args.kwargs
+
+ assert call_args == {
+ "body": "DISK at 99%",
+ "notify_type": NotifyType.FAILURE,
+ "title": None,
+ "body_format": NotifyFormat.TEXT,
+ "tag": "all",
+ "attach": None,
+ "interpret_escapes": None,
+ "config": None,
+ }
+ mock_apprise_hook.return_value.notify.assert_called_once()
@mock.patch("airflow.providers.apprise.notifications.apprise.AppriseHook")
- def test_notifier_with_notifier_class(self, mock_apprise_hook, dag_maker):
- with dag_maker("test_notifier") as dag:
- EmptyOperator(task_id="task1")
+ def test_notifier_with_notifier_class(self, mock_apprise_hook,
create_dag_without_db):
notifier = AppriseNotifier(body="DISK at 99%",
notify_type=NotifyType.FAILURE)
- notifier({"dag": dag})
- mock_apprise_hook.return_value.notify.assert_called_once_with(
- body="DISK at 99%",
- notify_type=NotifyType.FAILURE,
- title=None,
- body_format=NotifyFormat.TEXT,
- tag="all",
- attach=None,
- interpret_escapes=None,
- config=None,
- )
+ notifier({"dag": create_dag_without_db("test_notifier")})
+ call_args = mock_apprise_hook.return_value.notify.call_args.kwargs
- @mock.patch("airflow.providers.apprise.notifications.apprise.AppriseHook")
- def test_notifier_templated(self, mock_apprise_hook, dag_maker):
- with dag_maker("test_notifier") as dag:
- EmptyOperator(task_id="task1")
+ assert call_args == {
+ "body": "DISK at 99%",
+ "notify_type": NotifyType.FAILURE,
+ "title": None,
+ "body_format": NotifyFormat.TEXT,
+ "tag": "all",
+ "attach": None,
+ "interpret_escapes": None,
+ "config": None,
+ }
+ mock_apprise_hook.return_value.notify.assert_called_once()
+ @mock.patch("airflow.providers.apprise.notifications.apprise.AppriseHook")
+ def test_notifier_templated(self, mock_apprise_hook,
create_dag_without_db):
notifier = AppriseNotifier(
notify_type=NotifyType.FAILURE,
title="DISK at 99% {{dag.dag_id}}",
body="System can crash soon {{dag.dag_id}}",
)
- context = {"dag": dag}
+ context = {"dag": create_dag_without_db("test_notifier")}
notifier(context)
- mock_apprise_hook.return_value.notify.assert_called_once_with(
- notify_type=NotifyType.FAILURE,
- title="DISK at 99% test_notifier",
- body="System can crash soon test_notifier",
- body_format=NotifyFormat.TEXT,
- tag="all",
- attach=None,
- interpret_escapes=None,
- config=None,
- )
+ call_args = mock_apprise_hook.return_value.notify.call_args.kwargs
+ assert call_args == {
+ "body": "System can crash soon test_notifier",
+ "title": "DISK at 99% test_notifier",
+ "notify_type": NotifyType.FAILURE,
+ "body_format": NotifyFormat.TEXT,
+ "tag": "all",
+ "attach": None,
+ "interpret_escapes": None,
+ "config": None,
+ }
+ mock_apprise_hook.return_value.notify.assert_called_once()