Debian Codegraph @

tests/test_plugin_zoom.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
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation 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 from unittest import mock
31
32 from helpers import AppriseURLTester
33 import pytest
34 import requests
35
36 from apprise import Apprise, NotifyType
37 from apprise.plugins.zoom import (
38 ZOOM_MODE_DEFAULT,
39 NotifyZoom,
40 ZoomMode,
41 )
42
43 logging.disable(logging.CRITICAL)
44
45 # Reusable test credentials
46 WEBHOOK_ID = "abcHook123"
47 TOKEN = "xyzVerify456"
48
49 # Our Testing URLs
50 apprise_url_tests = (
51 # Missing everything
52 (
53 "zoom://",
54 {
55 "instance": TypeError,
56 },
57 ),
58 # Empty user/host segment
59 (
60 "zoom://:@/",
61 {
62 "instance": TypeError,
63 },
64 ),
65 # Missing token (webhook_id present but no path segment)
66 (
67 "zoom://{}".format(WEBHOOK_ID),
68 {
69 "instance": TypeError,
70 },
71 ),
72 # Valid full-mode (default)
73 (
74 "zoom://{}/{}".format(WEBHOOK_ID, TOKEN),
75 {
76 "instance": NotifyZoom,
77 "privacy_url": "zoom://a...3/x...6/",
78 },
79 ),
80 # Explicit mode=full
81 (
82 "zoom://{}/{}?mode=full".format(WEBHOOK_ID, TOKEN),
83 {
84 "instance": NotifyZoom,
85 "privacy_url": "zoom://a...3/x...6/",
86 },
87 ),
88 # Explicit mode=simple
89 (
90 "zoom://{}/{}?mode=simple".format(WEBHOOK_ID, TOKEN),
91 {
92 "instance": NotifyZoom,
93 "privacy_url": "zoom://a...3/x...6/",
94 },
95 ),
96 # Invalid mode
97 (
98 "zoom://{}/{}?mode=invalid".format(WEBHOOK_ID, TOKEN),
99 {
100 "instance": TypeError,
101 },
102 ),
103 # Native URL with ?token= query param
104 (
105 "https://inbots.zoom.us/incoming/hook/{}?token={}".format(
106 WEBHOOK_ID, TOKEN
107 ),
108 {
109 "instance": NotifyZoom,
110 },
111 ),
112 # Full mode: HTTP 500
113 (
114 "zoom://{}/{}".format(WEBHOOK_ID, TOKEN),
115 {
116 "instance": NotifyZoom,
117 "response": False,
118 "requests_response_code": (requests.codes.internal_server_error),
119 },
120 ),
121 # Full mode: unusual status code
122 (
123 "zoom://{}/{}".format(WEBHOOK_ID, TOKEN),
124 {
125 "instance": NotifyZoom,
126 "response": False,
127 "requests_response_code": 999,
128 },
129 ),
130 # Full mode: request exception
131 (
132 "zoom://{}/{}".format(WEBHOOK_ID, TOKEN),
133 {
134 "instance": NotifyZoom,
135 "test_requests_exceptions": True,
136 },
137 ),
138 # Simple mode: HTTP 500
139 (
140 "zoom://{}/{}?mode=simple".format(WEBHOOK_ID, TOKEN),
141 {
142 "instance": NotifyZoom,
143 "response": False,
144 "requests_response_code": (requests.codes.internal_server_error),
145 },
146 ),
147 # Simple mode: unusual status code
148 (
149 "zoom://{}/{}?mode=simple".format(WEBHOOK_ID, TOKEN),
150 {
151 "instance": NotifyZoom,
152 "response": False,
153 "requests_response_code": 999,
154 },
155 ),
156 # Simple mode: request exception
157 (
158 "zoom://{}/{}?mode=simple".format(WEBHOOK_ID, TOKEN),
159 {
160 "instance": NotifyZoom,
161 "test_requests_exceptions": True,
162 },
163 ),
164 )
165
166
167 def test_plugin_zoom_urls():
168 """NotifyZoom() Apprise URLs."""
169 AppriseURLTester(tests=apprise_url_tests).run_all()
170
171
172 def test_plugin_zoom_init():
173 """Test NotifyZoom initialization and validation."""
174
175 # Missing webhook_id
176 with pytest.raises(TypeError):
177 NotifyZoom(webhook_id=None, token=TOKEN)
178
179 # Empty webhook_id
180 with pytest.raises(TypeError):
181 NotifyZoom(webhook_id="", token=TOKEN)
182
183 # Webhook ID with invalid characters (slash)
184 with pytest.raises(TypeError):
185 NotifyZoom(webhook_id="bad/id", token=TOKEN)
186
187 # Missing token
188 with pytest.raises(TypeError):
189 NotifyZoom(webhook_id=WEBHOOK_ID, token=None)
190
191 # Empty token
192 with pytest.raises(TypeError):
193 NotifyZoom(webhook_id=WEBHOOK_ID, token="")
194
195 # Invalid mode
196 with pytest.raises(TypeError):
197 NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="bogus")
198
199 # Empty string mode is also invalid (must not silently resolve to simple)
200 with pytest.raises(TypeError):
201 NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="")
202
203 # Whitespace-only mode is also invalid
204 with pytest.raises(TypeError):
205 NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode=" ")
206
207 # Valid: default mode
208 obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN)
209 assert obj.mode == ZOOM_MODE_DEFAULT
210
211 # Valid: explicit full mode
212 obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="full")
213 assert obj.mode == ZoomMode.FULL
214
215 # Valid: explicit simple mode
216 obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="simple")
217 assert obj.mode == ZoomMode.SIMPLE
218
219 # Partial prefix matching: "sim" -> "simple"
220 obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="sim")
221 assert obj.mode == ZoomMode.SIMPLE
222
223 # Partial prefix matching: "f" -> "full"
224 obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="f")
225 assert obj.mode == ZoomMode.FULL
226
227
228 def test_plugin_zoom_url_round_trip():
229 """Verify that url() -> parse_url() -> __init__ is lossless."""
230
231 # Full mode round-trip
232 obj1 = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="full")
233 result = NotifyZoom.parse_url(obj1.url())
234 obj2 = NotifyZoom(**result)
235 assert obj1.url_identifier == obj2.url_identifier
236 assert obj1.mode == obj2.mode
237
238 # Simple mode round-trip
239 obj1 = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="simple")
240 result = NotifyZoom.parse_url(obj1.url())
241 obj2 = NotifyZoom(**result)
242 assert obj1.url_identifier == obj2.url_identifier
243 assert obj1.mode == obj2.mode
244
245
246 def test_plugin_zoom_url_privacy():
247 """Verify url(privacy=True) masks webhook_id and token."""
248 obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN)
249 priv = obj.url(privacy=True)
250 assert WEBHOOK_ID not in priv
251 assert TOKEN not in priv
252 # Schema is still present
253 assert priv.startswith("zoom://")
254
255
256 def test_plugin_zoom_url_identifier():
257 """Verify url_identifier contains webhook_id, token, and mode."""
258 obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN)
259 uid = obj.url_identifier
260 assert "zoom" in uid
261 assert WEBHOOK_ID in uid
262 assert TOKEN in uid
263
264 # Two instances with different tokens are distinct
265 obj2 = NotifyZoom(webhook_id=WEBHOOK_ID, token="other")
266 assert obj.url_identifier != obj2.url_identifier
267
268 # Same credentials but different modes produce different identifiers
269 obj_full = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="full")
270 obj_simple = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="simple")
271 assert obj_full.url_identifier != obj_simple.url_identifier
272 # mode is the 4th element (index 3) of the identifier tuple
273 assert obj_full.url_identifier[3] == ZoomMode.FULL
274 assert obj_simple.url_identifier[3] == ZoomMode.SIMPLE
275
276
277 @mock.patch("requests.post")
278 def test_plugin_zoom_full_send(mock_post):
279 """Test _send_full() success and failure paths."""
280
281 def _mk_resp(code=requests.codes.ok):
282 r = mock.Mock()
283 r.status_code = code
284 r.content = b""
285 return r
286
287 mock_post.return_value = _mk_resp()
288
289 # Success: with title
290 obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN)
291 assert obj.notify(
292 body="body text",
293 title="My Title",
294 notify_type=NotifyType.INFO,
295 )
296 assert mock_post.call_count == 1
297 # Verify ?format=full in URL
298 call_url = mock_post.call_args[0][0]
299 assert "format=full" in call_url
300
301 mock_post.reset_mock()
302
303 # Success: without title (no head section)
304 assert obj.notify(
305 body="body only",
306 title="",
307 notify_type=NotifyType.INFO,
308 )
309 assert mock_post.call_count == 1
310
311 mock_post.reset_mock()
312
313 # HTTP 204 is also a success
314 mock_post.return_value = _mk_resp(requests.codes.no_content)
315 assert obj.notify(body="test", notify_type=NotifyType.INFO)
316
317 mock_post.reset_mock()
318
319 # HTTP 500 -> failure
320 mock_post.return_value = _mk_resp(requests.codes.internal_server_error)
321 assert not obj.notify(body="test", notify_type=NotifyType.INFO)
322
323 mock_post.reset_mock()
324
325 # Unknown status code -> failure
326 mock_post.return_value = _mk_resp(999)
327 assert not obj.notify(body="test", notify_type=NotifyType.INFO)
328
329 mock_post.reset_mock()
330
331 # RequestException -> failure
332 mock_post.side_effect = requests.RequestException("boom")
333 assert not obj.notify(body="test", notify_type=NotifyType.INFO)
334
335
336 @mock.patch("requests.post")
337 def test_plugin_zoom_simple_send(mock_post):
338 """Test _send_simple() success and failure paths."""
339
340 def _mk_resp(code=requests.codes.ok):
341 r = mock.Mock()
342 r.status_code = code
343 r.content = b""
344 return r
345
346 mock_post.return_value = _mk_resp()
347
348 # Create a simple-mode instance
349 obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="simple")
350
351 # Success: with title (title prepended to body)
352 assert obj.notify(
353 body="msg body",
354 title="Alert",
355 notify_type=NotifyType.INFO,
356 )
357 assert mock_post.call_count == 1
358 # Verify no ?format= in simple mode URL
359 call_url = mock_post.call_args[0][0]
360 assert "format" not in call_url
361
362 mock_post.reset_mock()
363
364 # Success: without title
365 assert obj.notify(
366 body="no title",
367 title="",
368 notify_type=NotifyType.INFO,
369 )
370
371 mock_post.reset_mock()
372
373 # HTTP 204 is also a success
374 mock_post.return_value = _mk_resp(requests.codes.no_content)
375 assert obj.notify(body="test", notify_type=NotifyType.INFO)
376
377 mock_post.reset_mock()
378
379 # HTTP 500 -> failure
380 mock_post.return_value = _mk_resp(requests.codes.internal_server_error)
381 assert not obj.notify(body="test", notify_type=NotifyType.INFO)
382
383 mock_post.reset_mock()
384
385 # Unknown status code -> failure
386 mock_post.return_value = _mk_resp(999)
387 assert not obj.notify(body="test", notify_type=NotifyType.INFO)
388
389 mock_post.reset_mock()
390
391 # RequestException -> failure
392 mock_post.side_effect = requests.RequestException("err")
393 assert not obj.notify(body="test", notify_type=NotifyType.INFO)
394
395
396 def test_plugin_zoom_parse_url():
397 """Exercise parse_url() edge cases."""
398
399 # Basic: webhook_id in host, token in path
400 result = NotifyZoom.parse_url("zoom://myhookid/mytoken/")
401 assert result["webhook_id"] == "myhookid"
402 assert result["token"] == "mytoken"
403
404 # ?token= override
405 result = NotifyZoom.parse_url("zoom://myhookid/?token=override123")
406 assert result["webhook_id"] == "myhookid"
407 assert result["token"] == "override123"
408
409 # ?mode= parameter
410 result = NotifyZoom.parse_url("zoom://myhookid/mytoken/?mode=simple")
411 assert result["mode"] == "simple"
412
413 # A URL that fails base parsing returns None
414 result = NotifyZoom.parse_url(None)
415 assert result is None
416
417
418 def test_plugin_zoom_parse_native_url():
419 """Exercise parse_native_url()."""
420
421 # Native URL with ?token= appended
422 result = NotifyZoom.parse_native_url(
423 "https://inbots.zoom.us/incoming/hook/{}?token={}".format(
424 WEBHOOK_ID, TOKEN
425 )
426 )
427 assert result is not None
428 assert result["webhook_id"] == WEBHOOK_ID
429 assert result["token"] == TOKEN
430
431 # Native URL without token -> parse succeeds but
432 # token will be None/missing (instantiation would fail)
433 result = NotifyZoom.parse_native_url(
434 "https://inbots.zoom.us/incoming/hook/{}".format(WEBHOOK_ID)
435 )
436 assert result is not None
437 assert result["webhook_id"] == WEBHOOK_ID
438
439 # Non-matching URL -> None
440 assert (
441 NotifyZoom.parse_native_url("https://example.com/not/a/zoom/url")
442 is None
443 )
444
445
446 @mock.patch("requests.post")
447 def test_plugin_zoom_apprise_integration(mock_post):
448 """Test end-to-end via Apprise.add() and Apprise.notify()."""
449 r = mock.Mock()
450 r.status_code = requests.codes.ok
451 r.content = b""
452 mock_post.return_value = r
453
454 app = Apprise()
455 assert app.add("zoom://{}/{}".format(WEBHOOK_ID, TOKEN))
456 assert app.notify(title="Hello", body="World")
457 assert mock_post.call_count == 1