Debian Codegraph @

tests/test_decorator_notify.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 from os.path import dirname, join
31
32 from apprise import (
33 Apprise,
34 AppriseAsset,
35 AppriseAttachment,
36 AppriseConfig,
37 NotificationManager,
38 common,
39 )
40 from apprise.decorators import notify
41 from apprise.decorators.base import CustomNotifyPlugin
42
43 logging.disable(logging.CRITICAL)
44
45 # Grant access to our Notification Manager Singleton
46 N_MGR = NotificationManager()
47
48 TEST_VAR_DIR = join(dirname(__file__), "var")
49
50
51 def test_notify_simple_decoration():
52 """decorators: Test simple @notify"""
53
54 # Verify our schema we're about to declare doesn't already exist
55 # in our schema map:
56 assert "utiltest" not in N_MGR
57
58 verify_obj = {}
59
60 # Define a function here on the spot
61 @notify(on="utiltest", name="Apprise @notify Decorator Testing")
62 def my_inline_notify_wrapper(
63 body, title, notify_type, attach, *args, **kwargs
64 ):
65
66 # Test our body (always present)
67 assert isinstance(body, str)
68
69 # Ensure content is of type utf-8
70 assert isinstance(body.encode("utf-8"), bytes)
71
72 if attach:
73 # attachment is always of type AppriseAttach
74 assert isinstance(attach, AppriseAttachment)
75
76 # Populate our object we can use to validate
77 verify_obj.update(
78 {
79 "body": body,
80 "title": title,
81 "notify_type": notify_type,
82 "attach": attach,
83 "args": args,
84 "kwargs": kwargs,
85 }
86 )
87
88 # Now after our hook being inline... it's been loaded
89 assert "utiltest" in N_MGR
90
91 # Create ourselves an apprise object
92 aobj = Apprise()
93
94 assert aobj.add("utiltest://") is True
95
96 assert len(verify_obj) == 0
97
98 assert (
99 aobj.notify(
100 "Hello World",
101 title="My Title",
102 # add some attachments too
103 attach=(
104 join(TEST_VAR_DIR, "apprise-test.gif"),
105 join(TEST_VAR_DIR, "apprise-test.png"),
106 ),
107 )
108 is True
109 )
110
111 # Our content was populated after the notify() call
112 assert len(verify_obj) > 0
113 assert verify_obj["body"] == "Hello World"
114 assert verify_obj["title"] == "My Title"
115 assert verify_obj["notify_type"] == common.NotifyType.INFO
116 assert isinstance(verify_obj["attach"], AppriseAttachment)
117 assert len(verify_obj["attach"]) == 2
118
119 # No format was defined
120 assert "body_format" in verify_obj["kwargs"]
121 assert verify_obj["kwargs"]["body_format"] is None
122
123 # The meta argument allows us to further parse the URL parameters
124 # specified
125 assert isinstance(verify_obj["kwargs"], dict)
126 assert "meta" in verify_obj["kwargs"]
127 assert isinstance(verify_obj["kwargs"]["meta"], dict)
128 assert len(verify_obj["kwargs"]["meta"]) == 4
129 assert "tag" in verify_obj["kwargs"]["meta"]
130
131 assert "asset" in verify_obj["kwargs"]["meta"]
132 assert isinstance(verify_obj["kwargs"]["meta"]["asset"], AppriseAsset)
133
134 assert verify_obj["kwargs"]["meta"]["schema"] == "utiltest"
135 assert verify_obj["kwargs"]["meta"]["url"] == "utiltest://"
136
137 # Reset our verify object (so it can be populated again)
138 verify_obj = {}
139
140 # Send unicode
141 assert aobj.notify("ツ".encode()) is True
142 # Our content was populated after the notify() call
143 assert len(verify_obj) > 0
144 assert verify_obj["body"] == "ツ" # content comes back as str (utf-8)
145 assert verify_obj["title"] == ""
146 assert verify_obj["notify_type"] == common.NotifyType.INFO
147 assert verify_obj["attach"] is None
148
149 # No format was defined
150 assert "body_format" in verify_obj["kwargs"]
151 assert verify_obj["kwargs"]["body_format"] is None
152
153 # The meta argument allows us to further parse the URL parameters
154 # specified
155 assert isinstance(verify_obj["kwargs"], dict)
156 assert "meta" in verify_obj["kwargs"]
157 assert isinstance(verify_obj["kwargs"]["meta"], dict)
158 assert len(verify_obj["kwargs"]["meta"]) == 4
159 assert "tag" in verify_obj["kwargs"]["meta"]
160
161 assert "asset" in verify_obj["kwargs"]["meta"]
162 assert isinstance(verify_obj["kwargs"]["meta"]["asset"], AppriseAsset)
163
164 assert verify_obj["kwargs"]["meta"]["schema"] == "utiltest"
165 assert verify_obj["kwargs"]["meta"]["url"] == "utiltest://"
166
167 # Reset our verify object (so it can be populated again)
168 verify_obj = {}
169
170 # Send utf-8 string
171 assert aobj.notify("ツ") is True
172
173 assert len(verify_obj) > 0
174 assert verify_obj["body"] == "ツ" # content comes back as str (utf-8)
175 assert verify_obj["title"] == ""
176 assert verify_obj["notify_type"] == common.NotifyType.INFO
177 assert verify_obj["attach"] is None
178
179 # No format was defined
180 assert "body_format" in verify_obj["kwargs"]
181 assert verify_obj["kwargs"]["body_format"] is None
182
183 # The meta argument allows us to further parse the URL parameters
184 # specified
185 assert isinstance(verify_obj["kwargs"], dict)
186 assert "meta" in verify_obj["kwargs"]
187 assert isinstance(verify_obj["kwargs"]["meta"], dict)
188 assert len(verify_obj["kwargs"]["meta"]) == 4
189 assert "tag" in verify_obj["kwargs"]["meta"]
190
191 assert "asset" in verify_obj["kwargs"]["meta"]
192 assert isinstance(verify_obj["kwargs"]["meta"]["asset"], AppriseAsset)
193
194 assert verify_obj["kwargs"]["meta"]["schema"] == "utiltest"
195 assert verify_obj["kwargs"]["meta"]["url"] == "utiltest://"
196
197 # Some cases that will fail internal validation:
198 # - No Body
199 assert aobj.notify("") is False
200 # - Title only
201 assert aobj.notify("", title="hello world!") is False
202
203 # Reset our verify object (so it can be populated again)
204 verify_obj = {}
205
206 # No Body but has attachment (valid)
207 assert (
208 aobj.notify("", attach=(join(TEST_VAR_DIR, "apprise-test.png"),))
209 is True
210 )
211
212 # Our content was populated after the notify() call
213 assert len(verify_obj) > 0
214 assert verify_obj["body"] == ""
215 assert verify_obj["title"] == ""
216 assert verify_obj["notify_type"] == common.NotifyType.INFO
217 assert isinstance(verify_obj["attach"], AppriseAttachment)
218 assert len(verify_obj["attach"]) == 1
219
220 # No format was defined
221 assert "body_format" in verify_obj["kwargs"]
222 assert verify_obj["kwargs"]["body_format"] is None
223
224 # The meta argument allows us to further parse the URL parameters
225 # specified
226 assert isinstance(verify_obj["kwargs"], dict)
227 assert "meta" in verify_obj["kwargs"]
228 assert isinstance(verify_obj["kwargs"]["meta"], dict)
229 assert len(verify_obj["kwargs"]["meta"]) == 4
230 assert "tag" in verify_obj["kwargs"]["meta"]
231
232 assert "asset" in verify_obj["kwargs"]["meta"]
233 assert isinstance(verify_obj["kwargs"]["meta"]["asset"], AppriseAsset)
234
235 assert verify_obj["kwargs"]["meta"]["schema"] == "utiltest"
236 assert verify_obj["kwargs"]["meta"]["url"] == "utiltest://"
237
238 # Reset our verify object (so it can be populated again)
239 verify_obj = {}
240
241 # We'll do another test now
242 assert (
243 aobj.notify(
244 "Hello Another World",
245 title="My Other Title",
246 body_format=common.NotifyFormat.HTML,
247 notify_type=common.NotifyType.WARNING,
248 )
249 is True
250 )
251
252 # Our content was populated after the notify() call
253 assert len(verify_obj) > 0
254 assert verify_obj["body"] == "Hello Another World"
255 assert verify_obj["title"] == "My Other Title"
256 assert verify_obj["notify_type"] == common.NotifyType.WARNING
257 # We have no attachments
258 assert verify_obj["attach"] is None
259
260 # No format was defined
261 assert "body_format" in verify_obj["kwargs"]
262 assert verify_obj["kwargs"]["body_format"] == common.NotifyFormat.HTML
263
264 # The meta argument allows us to further parse the URL parameters
265 # specified
266 assert "meta" in verify_obj["kwargs"]
267 assert isinstance(verify_obj["kwargs"], dict)
268 assert len(verify_obj["kwargs"]["meta"]) == 4
269 assert "asset" in verify_obj["kwargs"]["meta"]
270 assert isinstance(verify_obj["kwargs"]["meta"]["asset"], AppriseAsset)
271 assert "tag" in verify_obj["kwargs"]["meta"]
272 assert isinstance(verify_obj["kwargs"]["meta"]["tag"], set)
273 assert verify_obj["kwargs"]["meta"]["schema"] == "utiltest"
274 assert verify_obj["kwargs"]["meta"]["url"] == "utiltest://"
275
276 assert "notexc" not in N_MGR
277
278 # Define a function here on the spot
279 @notify(on="notexc", name="Apprise @notify Exception Handling")
280 def my_exception_inline_notify_wrapper(
281 body, title, notify_type, attach, *args, **kwargs
282 ):
283 raise ValueError("An exception was thrown!")
284
285 assert "notexc" in N_MGR
286
287 # Create ourselves an apprise object
288 aobj = Apprise()
289
290 assert aobj.add("notexc://") is True
291
292 # Isn't handled
293 assert aobj.notify("Exceptions will be thrown!") is False
294
295 # Tidy
296 N_MGR.remove("utiltest", "notexc")
297
298
299 def test_notify_complex_decoration():
300 """decorators: Test complex @notify"""
301
302 # Verify our schema we're about to declare doesn't already exist
303 # in our schema map:
304 assert "utiltest" not in N_MGR
305
306 verify_obj = {}
307
308 # Define a function here on the spot
309 @notify(
310 on="utiltest://user@myhost:23?key=value&NOT=CaseSensitive",
311 name="Apprise @notify Decorator Testing",
312 )
313 def my_inline_notify_wrapper(
314 body, title, notify_type, attach, *args, **kwargs
315 ):
316
317 # Populate our object we can use to validate
318 verify_obj.update(
319 {
320 "body": body,
321 "title": title,
322 "notify_type": notify_type,
323 "attach": attach,
324 "args": args,
325 "kwargs": kwargs,
326 }
327 )
328
329 # Now after our hook being inline... it's been loaded
330 assert "utiltest" in N_MGR
331
332 # Create ourselves an apprise object
333 aobj = Apprise()
334
335 assert aobj.add("utiltest://") is True
336
337 assert len(verify_obj) == 0
338
339 assert (
340 aobj.notify(
341 "Hello World",
342 title="My Title",
343 # add some attachments too
344 attach=(
345 join(TEST_VAR_DIR, "apprise-test.gif"),
346 join(TEST_VAR_DIR, "apprise-test.png"),
347 ),
348 )
349 is True
350 )
351
352 # Our content was populated after the notify() call
353 assert len(verify_obj) > 0
354 assert verify_obj["body"] == "Hello World"
355 assert verify_obj["title"] == "My Title"
356 assert verify_obj["notify_type"] == common.NotifyType.INFO
357 assert isinstance(verify_obj["attach"], AppriseAttachment)
358 assert len(verify_obj["attach"]) == 2
359
360 # No format was defined
361 assert "body_format" in verify_obj["kwargs"]
362 assert verify_obj["kwargs"]["body_format"] is None
363
364 # The meta argument allows us to further parse the URL parameters
365 # specified
366 assert isinstance(verify_obj["kwargs"], dict)
367 assert "meta" in verify_obj["kwargs"]
368 assert isinstance(verify_obj["kwargs"]["meta"], dict)
369
370 assert "asset" in verify_obj["kwargs"]["meta"]
371 assert isinstance(verify_obj["kwargs"]["meta"]["asset"], AppriseAsset)
372
373 assert "tag" in verify_obj["kwargs"]["meta"]
374 assert isinstance(verify_obj["kwargs"]["meta"]["tag"], set)
375
376 assert len(verify_obj["kwargs"]["meta"]) == 8
377 # We carry all of our default arguments from the @notify's initialization
378 assert verify_obj["kwargs"]["meta"]["schema"] == "utiltest"
379
380 # Case sensitivity is lost on key assignment and always made lowercase
381 # however value case sensitivity is preseved.
382 # this is the assembled URL based on the combined values of the default
383 # parameters with values provided in the URL (user's configuration)
384 assert verify_obj["kwargs"]["meta"]["url"].startswith(
385 "utiltest://user@myhost:23?"
386 )
387
388 # We don't know where they get placed, so just search for their match
389 assert "key=value" in verify_obj["kwargs"]["meta"]["url"]
390 assert "not=CaseSensitive" in verify_obj["kwargs"]["meta"]["url"]
391
392 # Reset our verify object (so it can be populated again)
393 verify_obj = {}
394
395 # We'll do another test now
396 aobj = Apprise()
397
398 assert aobj.add("utiltest://customhost?key=new&key2=another") is True
399
400 assert len(verify_obj) == 0
401
402 # Send our notification
403 assert aobj.notify("Hello World", title="My Title") is True
404
405 # Our content was populated after the notify() call
406 assert len(verify_obj) > 0
407 assert verify_obj["body"] == "Hello World"
408 assert verify_obj["title"] == "My Title"
409 assert verify_obj["notify_type"] == common.NotifyType.INFO
410 assert verify_obj["attach"] is None
411
412 # No format was defined
413 assert "body_format" in verify_obj["kwargs"]
414 assert verify_obj["kwargs"]["body_format"] is None
415
416 # The meta argument allows us to further parse the URL parameters
417 # specified
418 assert "meta" in verify_obj["kwargs"]
419 assert isinstance(verify_obj["kwargs"], dict)
420 assert len(verify_obj["kwargs"]["meta"]) == 8
421
422 # We carry all of our default arguments from the @notify's initialization
423 assert verify_obj["kwargs"]["meta"]["schema"] == "utiltest"
424 # Our host get's correctly over-ridden
425 assert verify_obj["kwargs"]["meta"]["host"] == "customhost"
426
427 assert verify_obj["kwargs"]["meta"]["user"] == "user"
428 assert verify_obj["kwargs"]["meta"]["port"] == 23
429 assert isinstance(verify_obj["kwargs"]["meta"]["qsd"], dict)
430 assert len(verify_obj["kwargs"]["meta"]["qsd"]) == 3
431 # our key is over-ridden
432 assert verify_obj["kwargs"]["meta"]["qsd"]["key"] == "new"
433 # Our other keys are preserved
434 assert verify_obj["kwargs"]["meta"]["qsd"]["not"] == "CaseSensitive"
435 # New keys are added
436 assert verify_obj["kwargs"]["meta"]["qsd"]["key2"] == "another"
437
438 # Case sensitivity is lost on key assignment and always made lowercase
439 # however value case sensitivity is preseved.
440 # this is the assembled URL based on the combined values of the default
441 # parameters with values provided in the URL (user's configuration)
442 assert verify_obj["kwargs"]["meta"]["url"].startswith(
443 "utiltest://user@customhost:23?"
444 )
445
446 # We don't know where they get placed, so just search for their match
447 assert "key=new" in verify_obj["kwargs"]["meta"]["url"]
448 assert "not=CaseSensitive" in verify_obj["kwargs"]["meta"]["url"]
449 assert "key2=another" in verify_obj["kwargs"]["meta"]["url"]
450
451 # Tidy
452 N_MGR.remove("utiltest")
453
454
455 def test_notify_decorator_urls_with_space():
456 """decorators: URLs containing spaces"""
457 # This is in relation to https://github.com/caronc/apprise/issues/1264
458
459 # Verify our schema we're about to declare doesn't already exist
460 # in our schema map:
461 assert "post" not in N_MGR
462
463 verify_obj = []
464
465 @notify(on="posts")
466 def apprise_custom_api_call_wrapper(
467 body, title, notify_type, attach, meta, *args, **kwargs
468 ):
469
470 # Track what is added
471 verify_obj.append(
472 {
473 "body": body,
474 "title": title,
475 "notify_type": notify_type,
476 "attach": attach,
477 "meta": meta,
478 "args": args,
479 "kwargs": kwargs,
480 }
481 )
482
483 assert "posts" in N_MGR
484
485 # Create ourselves an apprise object
486 aobj = Apprise()
487
488 # Add our configuration
489 aobj.add("posts://example.com/my endpoint?-token=ab cdefg")
490
491 # We loaded 1 item
492 assert len(aobj) == 1
493
494 # Nothing stored yet in our object
495 assert len(verify_obj) == 0
496
497 # Send utf-8 characters
498 assert aobj.notify("ツ".encode(), title="My Title") is True
499
500 # Service notified
501 assert len(verify_obj) == 1
502
503 # Extract our object
504 obj = verify_obj.pop()
505
506 assert obj.get("body") == "ツ"
507 assert obj.get("title") == "My Title"
508 assert obj.get("notify_type") == "info"
509 assert obj.get("attach") is None
510 assert isinstance(obj.get("args"), tuple)
511 assert len(obj.get("args")) == 0
512 assert obj.get("kwargs") == {"body_format": None}
513 meta = obj.get("meta")
514 assert isinstance(meta, dict)
515
516 assert meta.get("schema") == "posts"
517 assert (
518 meta.get("url")
519 == "posts://example.com/my%20endpoint?-token=ab%20cdefg"
520 )
521 assert meta.get("qsd") == {"-token": "ab cdefg"}
522 assert meta.get("host") == "example.com"
523 assert meta.get("fullpath") == "/my%20endpoint"
524 assert meta.get("path") == "/"
525 assert meta.get("query") == "my%20endpoint"
526 assert isinstance(meta.get("tag"), set)
527 assert len(meta.get("tag")) == 0
528 assert isinstance(meta.get("asset"), AppriseAsset)
529
530 # Tidy
531 N_MGR.remove("posts")
532
533
534 def test_notify_multi_instance_decoration(tmpdir):
535 """decorators: Test multi-instance @notify"""
536
537 # Verify our schema we're about to declare doesn't already exist
538 # in our schema map:
539 assert "multi" not in N_MGR
540
541 verify_obj = []
542
543 # Define a function here on the spot
544 @notify(on="multi", name="Apprise @notify Decorator Testing")
545 def my_inline_notify_wrapper(
546 body, title, notify_type, attach, meta, *args, **kwargs
547 ):
548
549 assert isinstance(body, str)
550
551 # Track what is added
552 verify_obj.append(
553 {
554 "body": body,
555 "title": title,
556 "notify_type": notify_type,
557 "attach": attach,
558 "meta": meta,
559 "args": args,
560 "kwargs": kwargs,
561 }
562 )
563
564 # Now after our hook being inline... it's been loaded
565 assert "multi" in N_MGR
566
567 # Prepare our config
568 t = tmpdir.mkdir("multi-test").join("apprise.yml")
569 t.write("""urls:
570 - multi://user1:pass@hostname
571 - multi://user2:pass2@hostname?verify=no
572 """)
573
574 # Create ourselves a config object
575 ac = AppriseConfig(paths=str(t))
576
577 # Create ourselves an apprise object
578 aobj = Apprise()
579
580 # Add our configuration
581 aobj.add(ac)
582
583 # The number of configuration files that exist
584 assert len(ac) == 1
585
586 # 2 notification endpoints are loaded
587 assert len(ac.servers()) == 2
588
589 # Nothing stored yet in our object
590 assert len(verify_obj) == 0
591
592 # Send utf-8 characters
593 assert aobj.notify("ツ".encode(), title="My Title") is True
594
595 assert len(verify_obj) == 2
596
597 # Python 3.6 does not nessisarily return list in order
598 # So let's be sure it's sorted by the user id field to make the remaining
599 # checks on this test easy
600 verify_obj = sorted(verify_obj, key=lambda x: x["meta"]["user"])
601
602 # Our content was populated after the notify() call
603 obj = verify_obj[0]
604 assert obj["body"] == "ツ"
605 assert obj["title"] == "My Title"
606 assert obj["notify_type"] == common.NotifyType.INFO
607
608 meta = obj["meta"]
609 assert isinstance(meta, dict)
610
611 # No format was defined
612 assert "body_format" in obj["kwargs"]
613 assert obj["kwargs"]["body_format"] is None
614
615 # The meta argument allows us to further parse the URL parameters
616 # specified
617 assert isinstance(obj["kwargs"], dict)
618
619 assert "asset" in meta
620 assert isinstance(meta["asset"], AppriseAsset)
621
622 assert "tag" in meta
623 assert isinstance(meta["tag"], set)
624
625 assert len(meta) == 8
626 # We carry all of our default arguments from the @notify's initialization
627 assert meta["schema"] == "multi"
628 assert meta["host"] == "hostname"
629 assert meta["user"] == "user1"
630 assert meta["verify"] is True
631 assert "redirect" not in meta # absent -- URLBase inherits asset default
632 assert meta["password"] == "pass"
633
634 # Verify our URL is correct
635 assert meta["url"] == "multi://user1:pass@hostname"
636
637 #
638 # Now verify our second URL saved correct
639 #
640
641 # Our content was populated after the notify() call
642 obj = verify_obj[1]
643 assert obj["body"] == "ツ"
644 assert obj["title"] == "My Title"
645 assert obj["notify_type"] == common.NotifyType.INFO
646
647 meta = obj["meta"]
648 assert isinstance(meta, dict)
649
650 # No format was defined
651 assert "body_format" in obj["kwargs"]
652 assert obj["kwargs"]["body_format"] is None
653
654 # The meta argument allows us to further parse the URL parameters
655 # specified
656 assert isinstance(obj["kwargs"], dict)
657
658 assert "asset" in meta
659 assert isinstance(meta["asset"], AppriseAsset)
660
661 assert "tag" in meta
662 assert isinstance(meta["tag"], set)
663
664 assert len(meta) == 9
665 # We carry all of our default arguments from the @notify's initialization
666 assert meta["schema"] == "multi"
667 assert meta["host"] == "hostname"
668 assert meta["user"] == "user2"
669 assert meta["password"] == "pass2"
670 assert meta["verify"] is False
671 assert "redirect" not in meta # absent -- URLBase inherits asset default
672 assert meta["qsd"]["verify"] == "no"
673
674 # Verify our URL is correct
675 assert meta["url"] == "multi://user2:pass2@hostname?verify=no"
676
677 # Tidy
678 N_MGR.remove("multi")
679
680
681 def test_notify_yaml_priority_over_qsd():
682 """
683 decorators: YAML tokens take priority over qsd for @notify plugins.
684
685 YAML > qsd > URL path must hold for ALL plugin types, including
686 @notify decorator plugins. Previously, @notify plugins kept qsd
687 intact for the second post_process_parse_url_results() call, which
688 allowed qsd to silently overwrite YAML-token values. The fix
689 re-applies YAML tokens after post_process to restore priority.
690
691 Also verifies qsd is still preserved in the meta dict (for raw
692 inspection) and that qsd still wins over URL-path when no YAML
693 token is present for a field.
694 """
695 from apprise.config import ConfigBase
696
697 assert "notifyverify" not in N_MGR
698
699 @notify(on="notifyverify", name="Test YAML priority @notify")
700 def _handler(body, title, notify_type, attach, meta, *args, **kwargs):
701 pass
702
703 assert "notifyverify" in N_MGR
704
705 # URL has ?verify=no&user=qsduser; YAML sibling says verify: yes
706 # and user: yamluser. YAML must win for both.
707 result, _ = ConfigBase.config_parse_yaml("""
708 urls:
709 - notifyverify://urluser:urlpass@hostname?verify=no&user=qsduser:
710 verify: yes
711 user: yamluser
712 """)
713
714 assert len(result) == 1
715 meta = result[0]._default_args
716
717 # qsd must be preserved intact for downstream meta inspection
718 assert isinstance(meta.get("qsd"), dict)
719 assert meta["qsd"].get("verify") == "no"
720 assert meta["qsd"].get("user") == "qsduser"
721
722 # YAML tokens must win over qsd
723 assert meta["verify"] is True
724 assert meta["user"] == "yamluser"
725
726 # When no YAML token is present for a field, qsd still wins over
727 # the URL-path value (qsd > URL path).
728 result2, _ = ConfigBase.config_parse_yaml("""
729 urls:
730 - notifyverify://urluser:urlpass@hostname?verify=no:
731 """)
732 assert len(result2) == 1
733 meta2 = result2[0]._default_args
734 assert meta2["verify"] is False # qsd wins over URLBase default
735 assert meta2["user"] == "urluser" # URL-path value (no qsd for user)
736
737 # Tidy
738 N_MGR.remove("notifyverify")
739
740
741 def test_custom_notify_plugin_decoration():
742 """decorators: CustomNotifyPlugin testing"""
743
744 CustomNotifyPlugin()