|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# (c) 2021-2023 The mqttwarn developers |
| 3 | +from unittest import mock |
| 4 | +from unittest.mock import call |
| 5 | + |
| 6 | +from mqttwarn.model import ProcessorItem as Item |
| 7 | +from mqttwarn.util import load_module_by_name |
| 8 | + |
| 9 | + |
| 10 | +@mock.patch("apprise.Apprise", create=True) |
| 11 | +@mock.patch("apprise.AppriseAsset", create=True) |
| 12 | +def test_ntfy_success(apprise_asset, apprise_mock, srv, caplog): |
| 13 | + module = load_module_by_name("mqttwarn.services.apprise_multi") |
| 14 | + |
| 15 | + item = Item( |
| 16 | + addrs=[ |
| 17 | + { |
| 18 | + "baseuri": "ntfy://user:password@ntfy.example.org/topic1/topic2?email=test@example.org", |
| 19 | + } |
| 20 | + ], |
| 21 | + title="⚽ Message title ⚽", |
| 22 | + message="⚽ Notification message ⚽", |
| 23 | + data={"priority": "high", "tags": "foo,bar", "click": "https://httpbin.org/headers"}, |
| 24 | + ) |
| 25 | + |
| 26 | + outcome = module.plugin(srv, item) |
| 27 | + |
| 28 | + assert apprise_mock.mock_calls == [ |
| 29 | + call(asset=mock.ANY), |
| 30 | + call().add( |
| 31 | + "ntfy://user:password@ntfy.example.org/topic1/topic2?email=test@example.org" |
| 32 | + "&click=https%3A%2F%2Fhttpbin.org%2Fheaders&priority=high&tags=foo%2Cbar" |
| 33 | + ), |
| 34 | + call().notify(body="⚽ Notification message ⚽", title="⚽ Message title ⚽"), |
| 35 | + call().notify().__bool__(), |
| 36 | + ] |
| 37 | + |
| 38 | + assert "Successfully sent message using Apprise" in caplog.messages |
| 39 | + assert outcome is True |
0 commit comments