Debian Codegraph @

tests/test_plugin_lametric.py

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