| 1 |
# BSD 2-Clause License |
| 2 |
# |
| 3 |
# Apprise - Push Notification Library. |
| 4 |
# Copyright (c) 2026, Chris Caron <[email protected]> |
| 5 |
# |
| 6 |
# Redistribution and use in source and binary forms, with or without |
| 7 |
# modification, are permitted provided that the following conditions are met: |
| 8 |
# |
| 9 |
# 1. Redistributions of source code must retain the above copyright notice, |
| 10 |
# this list of conditions and the following disclaimer. |
| 11 |
# |
| 12 |
# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 |
# this list of conditions and the following disclaimer in the documentation |
| 14 |
# and/or other materials provided with the distribution. |
| 15 |
# |
| 16 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 20 |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 |
# POSSIBILITY OF SUCH DAMAGE.# BSD 2-Clause License |
| 27 |
|
| 28 |
from json import dumps |
| 29 |
|
| 30 |
# Disable logging for a cleaner testing output |
| 31 |
import logging |
| 32 |
|
| 33 |
from helpers import AppriseURLTester |
| 34 |
|
| 35 |
from apprise import Apprise, NotifyFormat |
| 36 |
from apprise.exception import AppriseImproperlyConfigured |
| 37 |
from apprise.plugins.signl4 import ( |
| 38 |
NotifySIGNL4, |
| 39 |
NotifyType, |
| 40 |
) |
| 41 |
|
| 42 |
logging.disable(logging.CRITICAL) |
| 43 |
|
| 44 |
SIGNL4_GOOD_RESPONSE = dumps( |
| 45 |
{ |
| 46 |
"eventId": "2516485120936941747_76d5cf30-27d2-4529-84ed-f31a8f2c72b1", |
| 47 |
} |
| 48 |
) |
| 49 |
|
| 50 |
# Our Testing URLs |
| 51 |
apprise_url_tests = ( |
| 52 |
( |
| 53 |
"signl4://", |
| 54 |
{ |
| 55 |
# We failed to identify any valid authentication |
| 56 |
"instance": AppriseImproperlyConfigured, |
| 57 |
}, |
| 58 |
), |
| 59 |
( |
| 60 |
"signl4://:@/", |
| 61 |
{ |
| 62 |
# We failed to identify any valid authentication |
| 63 |
"instance": AppriseImproperlyConfigured, |
| 64 |
}, |
| 65 |
), |
| 66 |
( |
| 67 |
"signl4://%20%20/", |
| 68 |
{ |
| 69 |
# invalid secret specified |
| 70 |
"instance": AppriseImproperlyConfigured, |
| 71 |
}, |
| 72 |
), |
| 73 |
( |
| 74 |
"signl4://secret/", |
| 75 |
{ |
| 76 |
# No targets specified; this is allowed |
| 77 |
"instance": NotifySIGNL4, |
| 78 |
"notify_type": NotifyType.FAILURE, |
| 79 |
# Our response expected server response |
| 80 |
"requests_response_text": SIGNL4_GOOD_RESPONSE, |
| 81 |
}, |
| 82 |
), |
| 83 |
( |
| 84 |
"signl4://?secret=secret", |
| 85 |
{ |
| 86 |
# No targets specified; this is allowed |
| 87 |
"instance": NotifySIGNL4, |
| 88 |
"notify_type": NotifyType.FAILURE, |
| 89 |
# Our response expected server response |
| 90 |
"requests_response_text": SIGNL4_GOOD_RESPONSE, |
| 91 |
}, |
| 92 |
), |
| 93 |
( |
| 94 |
"signl4://secret/?service=IoT", |
| 95 |
{ |
| 96 |
# European Region |
| 97 |
"instance": NotifySIGNL4, |
| 98 |
"notify_type": NotifyType.FAILURE, |
| 99 |
# Our response expected server response |
| 100 |
"requests_response_text": SIGNL4_GOOD_RESPONSE, |
| 101 |
}, |
| 102 |
), |
| 103 |
( |
| 104 |
"signl4://secret/?filtering=yes", |
| 105 |
{ |
| 106 |
# European Region |
| 107 |
"instance": NotifySIGNL4, |
| 108 |
"notify_type": NotifyType.FAILURE, |
| 109 |
# Our response expected server response |
| 110 |
"requests_response_text": SIGNL4_GOOD_RESPONSE, |
| 111 |
}, |
| 112 |
), |
| 113 |
( |
| 114 |
"signl4://secret/?location=40.6413111,-73.7781391", |
| 115 |
{ |
| 116 |
# European Region |
| 117 |
"instance": NotifySIGNL4, |
| 118 |
"notify_type": NotifyType.FAILURE, |
| 119 |
# Our response expected server response |
| 120 |
"requests_response_text": SIGNL4_GOOD_RESPONSE, |
| 121 |
}, |
| 122 |
), |
| 123 |
( |
| 124 |
"signl4://secret/?alerting_scenario=singl4_ack", |
| 125 |
{ |
| 126 |
# European Region |
| 127 |
"instance": NotifySIGNL4, |
| 128 |
"notify_type": NotifyType.FAILURE, |
| 129 |
# Our response expected server response |
| 130 |
"requests_response_text": SIGNL4_GOOD_RESPONSE, |
| 131 |
}, |
| 132 |
), |
| 133 |
( |
| 134 |
"signl4://secret/?filtering=False", |
| 135 |
{ |
| 136 |
# European Region |
| 137 |
"instance": NotifySIGNL4, |
| 138 |
"notify_type": NotifyType.FAILURE, |
| 139 |
# Our response expected server response |
| 140 |
"requests_response_text": SIGNL4_GOOD_RESPONSE, |
| 141 |
}, |
| 142 |
), |
| 143 |
( |
| 144 |
"signl4://secret/?external_id=ar1234&status=new", |
| 145 |
{ |
| 146 |
# European Region |
| 147 |
"instance": NotifySIGNL4, |
| 148 |
"notify_type": NotifyType.FAILURE, |
| 149 |
# Our response expected server response |
| 150 |
"requests_response_text": SIGNL4_GOOD_RESPONSE, |
| 151 |
}, |
| 152 |
), |
| 153 |
( |
| 154 |
( |
| 155 |
"signl4://secret/?service=IoT&location=40.6413111,-73.7781391" |
| 156 |
"&alerting_scenario=multi_ack&filtering=yes&external_id=ar1234" |
| 157 |
"&status=new" |
| 158 |
), |
| 159 |
{ |
| 160 |
# All of our supported parameters at once |
| 161 |
"instance": NotifySIGNL4, |
| 162 |
"notify_type": NotifyType.FAILURE, |
| 163 |
# Our response expected server response |
| 164 |
"requests_response_text": SIGNL4_GOOD_RESPONSE, |
| 165 |
# Our parameters are all present in the generated URL |
| 166 |
"privacy_url": "signl4://****/?service=IoT", |
| 167 |
}, |
| 168 |
), |
| 169 |
( |
| 170 |
"signl4://secret/", |
| 171 |
{ |
| 172 |
"instance": NotifySIGNL4, |
| 173 |
# throw a bizarre code forcing us to fail to look it up |
| 174 |
"response": False, |
| 175 |
"requests_response_code": 999, |
| 176 |
}, |
| 177 |
), |
| 178 |
( |
| 179 |
"signl4://secret/", |
| 180 |
{ |
| 181 |
"instance": NotifySIGNL4, |
| 182 |
# Throws a series of i/o exceptions with this flag |
| 183 |
# is set and tests that we gracefully handle them |
| 184 |
"test_requests_exceptions": True, |
| 185 |
}, |
| 186 |
), |
| 187 |
) |
| 188 |
|
| 189 |
|
| 190 |
def test_plugin_signl4_urls(): |
| 191 |
"""NotifySIGNL4() Apprise URLs.""" |
| 192 |
|
| 193 |
# Run our general tests |
| 194 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 195 |
|
| 196 |
|
| 197 |
def test_plugin_signl4_url_round_trip(): |
| 198 |
"""NotifySIGNL4() URL Round Trip.""" |
| 199 |
|
| 200 |
url = ( |
| 201 |
"signl4://secret/?service=IoT&location=40.6413111,-73.7781391" |
| 202 |
"&alerting_scenario=multi_ack&filtering=yes&external_id=ar1234" |
| 203 |
"&status=new&format=markdown&verify=no" |
| 204 |
) |
| 205 |
|
| 206 |
obj = Apprise.instantiate(url) |
| 207 |
assert isinstance(obj, NotifySIGNL4) |
| 208 |
|
| 209 |
# Our URL is re-loadable and nothing is lost along the way |
| 210 |
new_obj = Apprise.instantiate(obj.url()) |
| 211 |
assert isinstance(new_obj, NotifySIGNL4) |
| 212 |
|
| 213 |
# Our SIGNL4 specific settings survive |
| 214 |
assert new_obj.secret == obj.secret == "secret" |
| 215 |
assert new_obj.service == obj.service == "IoT" |
| 216 |
assert new_obj.location == obj.location == "40.6413111,-73.7781391" |
| 217 |
assert new_obj.alerting_scenario == obj.alerting_scenario == "multi_ack" |
| 218 |
assert new_obj.filtering is obj.filtering is True |
| 219 |
assert new_obj.external_id == obj.external_id == "ar1234" |
| 220 |
assert new_obj.status == obj.status == "new" |
| 221 |
|
| 222 |
# Our base settings survive too |
| 223 |
assert new_obj.notify_format == obj.notify_format == NotifyFormat.MARKDOWN |
| 224 |
assert new_obj.verify_certificate is obj.verify_certificate is False |
| 225 |
|
| 226 |
# A second pass produces the exact same URL |
| 227 |
assert new_obj.url() == obj.url() |
| 228 |
|
| 229 |
|
| 230 |
def test_plugin_signl4_filtering_parsing(): |
| 231 |
"""NotifySIGNL4() filtering= survives a percent encoded value.""" |
| 232 |
|
| 233 |
# An escaped percent sign reaches the plugin still encoded, so the |
| 234 |
# value has to make it through unquote() without tripping over it |
| 235 |
obj = Apprise.instantiate("signl4://secret/?filtering=%2579es") |
| 236 |
assert isinstance(obj, NotifySIGNL4) |
| 237 |
assert obj.filtering is True |
| 238 |
|
| 239 |
# An unparseable value falls back on the documented default |
| 240 |
obj = Apprise.instantiate("signl4://secret/?filtering=%25zz") |
| 241 |
assert isinstance(obj, NotifySIGNL4) |
| 242 |
assert obj.filtering is NotifySIGNL4.template_args["filtering"]["default"] |