Skip to content

Commit 7ddf6f0

Browse files
committed
apprise_single service: Add backward compatibility with "apprise.py"
1 parent 25a2cfc commit 7ddf6f0

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

HANDBOOK.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ launch = apprise-mail, apprise-json, apprise-discord
533533
[config:apprise-mail]
534534
; Dispatch message as e-mail.
535535
; https://github.com/caronc/apprise/wiki/Notify_email
536-
module = 'apprise'
536+
module = 'apprise_single'
537537
baseuri = 'mailtos://smtp_username:[email protected]'
538538
539539
sender_name = 'Example Monitoring'
@@ -544,7 +544,7 @@ targets = {
544544
[config:apprise-json]
545545
; Dispatch message to HTTP endpoint, in JSON format.
546546
; https://github.com/caronc/apprise/wiki/Notify_Custom_JSON
547-
module = 'apprise'
547+
module = 'apprise_single'
548548
baseuri = 'json://localhost:1234/mqtthook'
549549
550550
[config:apprise-discord]

mqttwarn/services/apprise.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from mqttwarn.services.apprise_single import plugin

tests/acme/foobar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
def plugin(srv, item):
22
srv.logging.debug("*** MODULE=%s: service=%s, target=%s", __file__, item.service, item.target)
3-
srv.logging.info("Plugin invoked.")
3+
srv.logging.info("Plugin invoked")

tests/services/test_apprise_single.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,32 @@ def test_apprise_success_with_sender(apprise_asset, apprise_mock, srv, caplog):
208208

209209
assert outcome is True
210210
assert "Successfully sent message using Apprise" in caplog.text
211+
212+
213+
@surrogate("apprise")
214+
@mock.patch("apprise.Apprise", create=True)
215+
@mock.patch("apprise.AppriseAsset", create=True)
216+
def test_apprise_success_backward_compat(apprise_asset, apprise_mock, srv, caplog):
217+
218+
with caplog.at_level(logging.DEBUG):
219+
220+
module = load_module_from_file("mqttwarn/services/apprise.py")
221+
222+
item = Item(
223+
config={"baseuri": "json://localhost:1234/mqtthook"},
224+
title="⚽ Message title ⚽",
225+
message="⚽ Notification message ⚽",
226+
)
227+
228+
outcome = module.plugin(srv, item)
229+
230+
assert apprise_mock.mock_calls == [
231+
call(asset=mock.ANY),
232+
call().add("json://localhost:1234/mqtthook"),
233+
call().notify(body="⚽ Notification message ⚽", title="⚽ Message title ⚽"),
234+
call().notify().__bool__(),
235+
]
236+
237+
assert outcome is True
238+
assert "Sending notification to Apprise. target=None, addresses=[]" in caplog.messages
239+
assert "Successfully sent message using Apprise" in caplog.messages

tests/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test_plugin_module(caplog, configfile):
194194
)
195195

196196
# Proof that the message has been routed to the "log" plugin properly
197-
assert "Plugin invoked" in caplog.text, caplog.text
197+
assert "Plugin invoked" in caplog.messages
198198

199199

200200
@pytest.mark.parametrize("configfile", [configfile_full, configfile_service_loading])
@@ -212,7 +212,7 @@ def test_plugin_file(caplog, configfile):
212212
send_message(topic="test/plugin-file", payload='{"name": "temperature", "value": 42.42}')
213213

214214
# Proof that the message has been routed to the "log" plugin properly
215-
assert "Plugin invoked" in caplog.text, caplog.text
215+
assert "Plugin invoked" in caplog.messages
216216

217217

218218
def test_xform_func(caplog):

0 commit comments

Comments
 (0)