| 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. |
| 27 |
|
| 28 |
# Disable logging for a cleaner testing output |
| 29 |
import logging |
| 30 |
|
| 31 |
from helpers import AppriseURLTester |
| 32 |
import pytest |
| 33 |
import requests |
| 34 |
|
| 35 |
from apprise.exception import AppriseImproperlyConfigured |
| 36 |
from apprise.plugins.lametric import NotifyLametric |
| 37 |
|
| 38 |
logging.disable(logging.CRITICAL) |
| 39 |
|
| 40 |
# a test UUID we can use |
| 41 |
UUID4 = "8b799edf-6f98-4d3a-9be7-2862fb4e5752" |
| 42 |
|
| 43 |
# Our Testing URLs |
| 44 |
apprise_url_tests = ( |
| 45 |
( |
| 46 |
"lametric://", |
| 47 |
{ |
| 48 |
# No APIKey or App ID specified |
| 49 |
"instance": AppriseImproperlyConfigured, |
| 50 |
}, |
| 51 |
), |
| 52 |
( |
| 53 |
"lametric://:@/", |
| 54 |
{ |
| 55 |
# No APIKey or App ID specified |
| 56 |
"instance": AppriseImproperlyConfigured, |
| 57 |
}, |
| 58 |
), |
| 59 |
( |
| 60 |
"lametric://{}/".format( |
| 61 |
"com.lametric.941c51dff3135bd87aa72db9d855dd50" |
| 62 |
), |
| 63 |
{ |
| 64 |
# No APIKey specified |
| 65 |
"instance": AppriseImproperlyConfigured, |
| 66 |
}, |
| 67 |
), |
| 68 |
( |
| 69 |
f"lametric://root:{UUID4}@192.168.0.5:8080/", |
| 70 |
{ |
| 71 |
# Everything is okay; this would be picked up in Device Mode |
| 72 |
# We're using a default port and enforcing a special user |
| 73 |
"instance": NotifyLametric, |
| 74 |
# Our expected url(privacy=True) startswith() response: |
| 75 |
"privacy_url": "lametric://root:[email protected]/", |
| 76 |
}, |
| 77 |
), |
| 78 |
( |
| 79 |
f"lametric://{UUID4}@192.168.0.4:8000/", |
| 80 |
{ |
| 81 |
# Everything is okay; this would be picked up in Device Mode |
| 82 |
# Port is enforced |
| 83 |
"instance": NotifyLametric, |
| 84 |
# Our expected url(privacy=True) startswith() response: |
| 85 |
"privacy_url": "lametric://[email protected]:8000/", |
| 86 |
}, |
| 87 |
), |
| 88 |
( |
| 89 |
f"lametric://{UUID4}@192.168.0.5/", |
| 90 |
{ |
| 91 |
# Everything is okay; this would be picked up in Device Mode |
| 92 |
"instance": NotifyLametric, |
| 93 |
# Our expected url(privacy=True) startswith() response: |
| 94 |
"privacy_url": "lametric://[email protected]/", |
| 95 |
}, |
| 96 |
), |
| 97 |
( |
| 98 |
f"lametrics://{UUID4}@192.168.0.6/?mode=device", |
| 99 |
{ |
| 100 |
# Everything is okay; Device mode forced |
| 101 |
"instance": NotifyLametric, |
| 102 |
# Our expected url(privacy=True) startswith() response: |
| 103 |
"privacy_url": "lametrics://[email protected]/", |
| 104 |
}, |
| 105 |
), |
| 106 |
# Support Native URL (with Access Token Argument) |
| 107 |
( |
| 108 |
"https://developer.lametric.com/api/v1/dev/widget/update/" |
| 109 |
"com.lametric.ABCD123/1?token={}==".format("D" * 88), |
| 110 |
{ |
| 111 |
# Everything is okay; Device mode forced |
| 112 |
"instance": NotifyLametric, |
| 113 |
# Our expected url(privacy=True) startswith() response: |
| 114 |
"privacy_url": "lametric://[email protected]/1/", |
| 115 |
}, |
| 116 |
), |
| 117 |
( |
| 118 |
"lametric://192.168.2.8/?mode=device&apikey=abc123", |
| 119 |
{ |
| 120 |
# Everything is okay; Device mode forced |
| 121 |
"instance": NotifyLametric, |
| 122 |
# Our expected url(privacy=True) startswith() response: |
| 123 |
"privacy_url": "lametric://[email protected]/", |
| 124 |
}, |
| 125 |
), |
| 126 |
( |
| 127 |
"lametrics://{}[email protected]/" |
| 128 |
"?mode=cloud&app_ver=2".format("A" * 88), |
| 129 |
{ |
| 130 |
# Everything is okay; Cloud mode forced |
| 131 |
# We gracefully strip off the com.lametric. part as well |
| 132 |
# We also set an application version of 2 |
| 133 |
"instance": NotifyLametric, |
| 134 |
# Our expected url(privacy=True) startswith() response: |
| 135 |
"privacy_url": "lametric://[email protected]/", |
| 136 |
}, |
| 137 |
), |
| 138 |
( |
| 139 |
"lametrics://{}[email protected]/" |
| 140 |
"?app_ver=invalid".format("A" * 88), |
| 141 |
{ |
| 142 |
# We set invalid app version |
| 143 |
"instance": AppriseImproperlyConfigured, |
| 144 |
}, |
| 145 |
), |
| 146 |
# our lametric object initialized via argument |
| 147 |
( |
| 148 |
"lametric://?app=com.lametric.941c51dff3135bd87aa72db9d855dd50&token={}==" |
| 149 |
"&mode=cloud".format("B" * 88), |
| 150 |
{ |
| 151 |
# Everything is okay; Cloud mode forced |
| 152 |
"instance": NotifyLametric, |
| 153 |
# Our expected url(privacy=True) startswith() response: |
| 154 |
"privacy_url": "lametric://[email protected]/", |
| 155 |
}, |
| 156 |
), |
| 157 |
( |
| 158 |
"lametrics://{}==@abcd/?mode=cloud&sound=knock&icon_type=info" |
| 159 |
"&priority=critical&cycles=10".format("C" * 88), |
| 160 |
{ |
| 161 |
# Cloud mode forced, sound, icon_type, and priority not supported |
| 162 |
# with cloud mode so warnings are created |
| 163 |
"instance": NotifyLametric, |
| 164 |
# Our expected url(privacy=True) startswith() response: |
| 165 |
"privacy_url": "lametric://[email protected]/", |
| 166 |
}, |
| 167 |
), |
| 168 |
( |
| 169 |
f"lametrics://{UUID4}@192.168.0.7/?mode=invalid", |
| 170 |
{ |
| 171 |
# Invalid Mode |
| 172 |
"instance": AppriseImproperlyConfigured, |
| 173 |
}, |
| 174 |
), |
| 175 |
( |
| 176 |
f"lametrics://{UUID4}@192.168.0.6/?sound=alarm1", |
| 177 |
{ |
| 178 |
# Device mode with sound set to alarm1 |
| 179 |
"instance": NotifyLametric, |
| 180 |
}, |
| 181 |
), |
| 182 |
( |
| 183 |
f"lametrics://{UUID4}@192.168.0.7/?sound=bike", |
| 184 |
{ |
| 185 |
# Device mode with sound set to bicycle using alias |
| 186 |
"instance": NotifyLametric, |
| 187 |
# Bike is an alias, |
| 188 |
"url_matches": r"sound=bicycle", |
| 189 |
}, |
| 190 |
), |
| 191 |
( |
| 192 |
f"lametrics://{UUID4}@192.168.0.8/?sound=invalid!", |
| 193 |
{ |
| 194 |
# Invalid sounds just produce warnings... object still loads |
| 195 |
"instance": NotifyLametric, |
| 196 |
}, |
| 197 |
), |
| 198 |
( |
| 199 |
f"lametrics://{UUID4}@192.168.0.9/?icon_type=alert", |
| 200 |
{ |
| 201 |
# Icon Type Changed |
| 202 |
"instance": NotifyLametric, |
| 203 |
# icon=alert exists somewhere on our generated URL |
| 204 |
"url_matches": r"icon_type=alert", |
| 205 |
}, |
| 206 |
), |
| 207 |
( |
| 208 |
f"lametrics://{UUID4}@192.168.0.10/?icon_type=invalid", |
| 209 |
{ |
| 210 |
# Invalid icon types just produce warnings... object still loads |
| 211 |
"instance": NotifyLametric, |
| 212 |
}, |
| 213 |
), |
| 214 |
( |
| 215 |
f"lametric://{UUID4}@192.168.1.1/?priority=warning", |
| 216 |
{ |
| 217 |
# Priority changed |
| 218 |
"instance": NotifyLametric, |
| 219 |
}, |
| 220 |
), |
| 221 |
( |
| 222 |
f"lametrics://{UUID4}@192.168.1.2/?priority=invalid", |
| 223 |
{ |
| 224 |
# Invalid priority just produce warnings... object still loads |
| 225 |
"instance": NotifyLametric, |
| 226 |
}, |
| 227 |
), |
| 228 |
( |
| 229 |
f"lametric://{UUID4}@192.168.1.2/?icon=230", |
| 230 |
{ |
| 231 |
# Our custom icon by it's ID |
| 232 |
"instance": NotifyLametric, |
| 233 |
}, |
| 234 |
), |
| 235 |
( |
| 236 |
f"lametrics://{UUID4}@192.168.1.2/?icon=#230", |
| 237 |
{ |
| 238 |
# Our custom icon by it's ID; the hashtag at the front is ignored |
| 239 |
"instance": NotifyLametric, |
| 240 |
}, |
| 241 |
), |
| 242 |
( |
| 243 |
f"lametric://{UUID4}@192.168.1.2/?icon=Heart", |
| 244 |
{ |
| 245 |
# Our custom icon; the hashtag at the front is ignored |
| 246 |
"instance": NotifyLametric, |
| 247 |
}, |
| 248 |
), |
| 249 |
( |
| 250 |
f"lametric://{UUID4}@192.168.1.2/?icon=#", |
| 251 |
{ |
| 252 |
# a hashtag and nothing else |
| 253 |
"instance": NotifyLametric, |
| 254 |
}, |
| 255 |
), |
| 256 |
( |
| 257 |
f"lametric://{UUID4}@192.168.1.2/?icon=#%20%20%20", |
| 258 |
{ |
| 259 |
# a hashtag and some spaces |
| 260 |
"instance": NotifyLametric, |
| 261 |
}, |
| 262 |
), |
| 263 |
( |
| 264 |
f"lametric://{UUID4}@192.168.1.3/?cycles=2", |
| 265 |
{ |
| 266 |
# Cycles changed |
| 267 |
"instance": NotifyLametric, |
| 268 |
}, |
| 269 |
), |
| 270 |
( |
| 271 |
f"lametric://{UUID4}@192.168.1.4/?cycles=-1", |
| 272 |
{ |
| 273 |
# Cycles changed (out of range) |
| 274 |
"instance": NotifyLametric, |
| 275 |
}, |
| 276 |
), |
| 277 |
( |
| 278 |
f"lametrics://{UUID4}@192.168.1.5/?cycles=invalid", |
| 279 |
{ |
| 280 |
# Invalid priority just produce warnings... object still loads |
| 281 |
"instance": NotifyLametric, |
| 282 |
}, |
| 283 |
), |
| 284 |
( |
| 285 |
f"lametric://{UUID4}@example.com/", |
| 286 |
{ |
| 287 |
"instance": NotifyLametric, |
| 288 |
# force a failure |
| 289 |
"response": False, |
| 290 |
"requests_response_code": requests.codes.internal_server_error, |
| 291 |
# Our expected url(privacy=True) startswith() response: |
| 292 |
"privacy_url": "lametric://[email protected]/", |
| 293 |
}, |
| 294 |
), |
| 295 |
( |
| 296 |
f"lametrics://{UUID4}@example.ca/", |
| 297 |
{ |
| 298 |
"instance": NotifyLametric, |
| 299 |
# throw a bizarre code forcing us to fail to look it up |
| 300 |
"response": False, |
| 301 |
"requests_response_code": 999, |
| 302 |
# Our expected url(privacy=True) startswith() response: |
| 303 |
"privacy_url": "lametrics://[email protected]/", |
| 304 |
}, |
| 305 |
), |
| 306 |
( |
| 307 |
f"lametrics://{UUID4}@example.net/", |
| 308 |
{ |
| 309 |
"instance": NotifyLametric, |
| 310 |
# Throws a series of i/o exceptions with this flag |
| 311 |
# is set and tests that we gracefully handle them |
| 312 |
"test_requests_exceptions": True, |
| 313 |
}, |
| 314 |
), |
| 315 |
) |
| 316 |
|
| 317 |
|
| 318 |
def test_plugin_lametric_urls(): |
| 319 |
"""NotifyLametric() Apprise URLs.""" |
| 320 |
|
| 321 |
# Run our general tests |
| 322 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 323 |
|
| 324 |
|
| 325 |
def test_plugin_lametric_edge_cases(): |
| 326 |
"""NotifyLametric() Edge Cases.""" |
| 327 |
# Initializes the plugin with an invalid API Key |
| 328 |
with pytest.raises(AppriseImproperlyConfigured): |
| 329 |
NotifyLametric(apikey=None, mode="device") |
| 330 |
|
| 331 |
# Initializes the plugin with an invalid Client Secret |
| 332 |
with pytest.raises(AppriseImproperlyConfigured): |
| 333 |
NotifyLametric(client_id="valid", secret=None, mode="cloud") |