@@ -31,15 +31,15 @@ def test_apprise_success(apprise_asset, apprise_mock, srv, caplog):
3131 assert apprise_mock .mock_calls == [
3232 call (asset = mock .ANY ),
3333 call ().add (
34- "mailtos://smtp_username:[email protected] ?from=None& to=foo@example .org,bar@example .org" 34+ "mailtos://smtp_username:[email protected] ?to=foo%40example .org%2Cbar%40example .org" 3535 ),
3636 call ().notify (body = "⚽ Notification message ⚽" , title = "⚽ Message title ⚽" ),
3737 call ().notify ().__bool__ (),
3838 ]
3939
4040 assert outcome is True
4141 assert (
42- "Sending notification to Apprise test, addresses: ['[email protected] ', '[email protected] ']" 42+ "Sending notification to Apprise. target= test, addresses= ['[email protected] ', '[email protected] ']" 4343 in caplog .text
4444 )
4545 assert "Successfully sent message using Apprise" in caplog .text
@@ -48,28 +48,40 @@ def test_apprise_success(apprise_asset, apprise_mock, srv, caplog):
4848@surrogate ("apprise" )
4949@mock .patch ("apprise.Apprise" , create = True )
5050@mock .patch ("apprise.AppriseAsset" , create = True )
51- def test_apprise_failure_no_addresses (apprise_asset , apprise_mock , srv , caplog ):
51+ def test_apprise_success_no_addresses (apprise_asset , apprise_mock , srv , caplog ):
52+ """
53+ Some Apprise notifiers don't need any target address information.
54+ Proof that also works by processing an `Item` with no `target`
55+ and `addrs` attributes supplied.
56+ """
5257
5358 with caplog .at_level (logging .DEBUG ):
5459
5560 module = load_module_from_file ("mqttwarn/services/apprise.py" )
5661
5762 item = Item (
58- config = {
"baseuri" :
"mailtos://smtp_username:[email protected] " },
59- target = "test" ,
60- addrs = [],
63+ config = {"baseuri" : "json://localhost:1234/mqtthook" },
6164 title = "⚽ Message title ⚽" ,
6265 message = "⚽ Notification message ⚽" ,
6366 )
6467
6568 outcome = module .plugin (srv , item )
6669
67- assert apprise_mock .mock_calls == []
70+ assert apprise_mock .mock_calls == [
71+ call (asset = mock .ANY ),
72+ call ().add (
73+ "json://localhost:1234/mqtthook"
74+ ),
75+ call ().notify (body = "⚽ Notification message ⚽" , title = "⚽ Message title ⚽" ),
76+ call ().notify ().__bool__ (),
77+ ]
6878
69- assert outcome is False
79+ assert outcome is True
7080 assert (
71- "Skipped sending notification to Apprise test, no addresses configured" in caplog .text
81+ "Sending notification to Apprise. target=None, addresses=[]"
82+ in caplog .messages
7283 )
84+ assert "Successfully sent message using Apprise" in caplog .messages
7385
7486
7587@surrogate ("apprise" )
@@ -106,13 +118,13 @@ def error(*args, **kwargs):
106118 ]
107119 assert mock_connection .mock_calls == [
108120 call .add (
109- "mailtos://smtp_username:[email protected] ?from=None& to=foo@example .org,bar@example .org" 121+ "mailtos://smtp_username:[email protected] ?to=foo%40example .org%2Cbar%40example .org" 110122 ),
111123 ]
112124
113125 assert outcome is False
114126 assert (
115- "Sending notification to Apprise test, addresses: ['[email protected] ', '[email protected] ']" 127+ "Sending notification to Apprise. target= test, addresses= ['[email protected] ', '[email protected] ']" 116128 in caplog .text
117129 )
118130 assert "Sending message using Apprise failed" in caplog .text
@@ -152,13 +164,13 @@ def error(*args, **kwargs):
152164 ]
153165 assert mock_connection .mock_calls == [
154166 call .add (
155- "mailtos://smtp_username:[email protected] ?from=None& to=foo@example .org,bar@example .org" 167+ "mailtos://smtp_username:[email protected] ?to=foo%40example .org%2Cbar%40example .org" 156168 ),
157169 ]
158170
159171 assert outcome is False
160172 assert (
161- "Sending notification to Apprise test, addresses: ['[email protected] ', '[email protected] ']" 173+ "Sending notification to Apprise. target= test, addresses= ['[email protected] ', '[email protected] ']" 162174 in caplog .text
163175 )
164176 assert "Error sending message to test: something failed" in caplog .text
@@ -190,7 +202,7 @@ def test_apprise_success_with_sender(apprise_asset, apprise_mock, srv, caplog):
190202 assert apprise_mock .mock_calls == [
191203 call (asset = mock .ANY ),
192204 call ().add (
193- "mailtos://smtp_username:[email protected] ?from=example@example .org&to=foo@example .org,bar@example .org&name=Max Mustermann" 205+ "mailtos://smtp_username:[email protected] ?from=example%40example .org&to=foo%40example .org%2Cbar%40example .org&name=Max+ Mustermann" 194206 ),
195207 call ().notify (body = "⚽ Notification message ⚽" , title = "⚽ Message title ⚽" ),
196208 call ().notify ().__bool__ (),
0 commit comments