Debian Codegraph @

tests/test_plugin_pagertree.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 unittest import mock
31
32 from helpers import AppriseURLTester
33 import pytest
34 import requests
35
36 from apprise.plugins.pagertree import NotifyPagerTree
37
38 logging.disable(logging.CRITICAL)
39
40 # a test UUID we can use
41 INTEGRATION_ID = "int_xxxxxxxxxxx"
42
43 # Our Testing URLs
44 apprise_url_tests = (
45 (
46 "pagertree://",
47 {
48 # Missing Integration ID
49 "instance": TypeError,
50 },
51 ),
52 # Invalid Integration ID
53 (
54 "pagertree://%s" % ("+" * 24),
55 {
56 "instance": TypeError,
57 },
58 ),
59 # Minimum requirements met
60 (
61 f"pagertree://{INTEGRATION_ID}",
62 {
63 "instance": NotifyPagerTree,
64 # Our expected url(privacy=True) startswith() response:
65 "privacy_url": "pagertree://i...x?",
66 },
67 ),
68 # change the integration id
69 (
70 f"pagertree://{INTEGRATION_ID}?integration=int_yyyyyyyyyy",
71 {
72 "instance": NotifyPagerTree,
73 # Our expected url(privacy=True) startswith() response:
74 "privacy_url": "pagertree://i...y?",
75 },
76 ),
77 # entries specified on the URL will over-ride the host (integration id)
78 (
79 f"pagertree://{INTEGRATION_ID}?id=int_zzzzzzzzzz",
80 {
81 "instance": NotifyPagerTree,
82 # Our expected url(privacy=True) startswith() response:
83 "privacy_url": "pagertree://i...z?",
84 },
85 ),
86 # Integration ID + bad url
87 (
88 "pagertree://:@/",
89 {
90 "instance": TypeError,
91 },
92 ),
93 (
94 f"pagertree://{INTEGRATION_ID}",
95 {
96 "instance": NotifyPagerTree,
97 # force a failure
98 "response": False,
99 "requests_response_code": requests.codes.internal_server_error,
100 },
101 ),
102 (
103 f"pagertree://{INTEGRATION_ID}",
104 {
105 "instance": NotifyPagerTree,
106 # throw a bizarre code forcing us to fail to look it up
107 "response": False,
108 "requests_response_code": 999,
109 },
110 ),
111 (
112 f"pagertree://{INTEGRATION_ID}",
113 {
114 "instance": NotifyPagerTree,
115 # Throws a series of i/o exceptions with this flag
116 # is set and tests that we gracefully handle them
117 "test_requests_exceptions": True,
118 },
119 ),
120 (
121 f"pagertree://{INTEGRATION_ID}?urgency=low",
122 {
123 # urgency override
124 "instance": NotifyPagerTree,
125 },
126 ),
127 (
128 f"pagertree://?id={INTEGRATION_ID}&urgency=low",
129 {
130 # urgency override and id= (for integration)
131 "instance": NotifyPagerTree,
132 },
133 ),
134 (
135 f"pagertree://{INTEGRATION_ID}?tags=production,web",
136 {
137 # tags
138 "instance": NotifyPagerTree,
139 },
140 ),
141 (
142 f"pagertree://{INTEGRATION_ID}?action=resolve&thirdparty=123",
143 {
144 # test resolve
145 "instance": NotifyPagerTree,
146 },
147 ),
148 # Custom values
149 (
150 f"pagertree://{INTEGRATION_ID}?+pagertree-token=123&:env=prod&-m=v",
151 {
152 # minimum requirements and support custom key/value pairs
153 "instance": NotifyPagerTree,
154 },
155 ),
156 )
157
158
159 def test_plugin_pagertree_urls():
160 """NotifyPagerTree() Apprise URLs."""
161
162 # Run our general tests
163 AppriseURLTester(tests=apprise_url_tests).run_all()
164
165
166 @mock.patch("requests.post")
167 def test_plugin_pagertree_general(mock_post):
168 """NotifyPagerTree() General Checks."""
169
170 # Prepare Mock
171 mock_post.return_value = requests.Request()
172 mock_post.return_value.status_code = requests.codes.ok
173
174 # Invalid thirdparty id
175 with pytest.raises(TypeError):
176 NotifyPagerTree(integration=INTEGRATION_ID, thirdparty=" ")