Debian Codegraph @

tests/test_plugin_splunk.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 requests
33
34 from apprise.plugins.splunk import NotifySplunk
35
36 logging.disable(logging.CRITICAL)
37
38 # Our Testing URLs
39 apprise_url_tests = (
40 (
41 "splunk://",
42 {
43 "instance": TypeError,
44 },
45 ),
46 (
47 "splunk://:@/",
48 {
49 "instance": TypeError,
50 },
51 ),
52 (
53 "splunk://routekey@%badapi%",
54 {
55 "instance": TypeError,
56 },
57 ),
58 (
59 "splunk://abc123",
60 {
61 # No route key provided
62 "instance": TypeError,
63 },
64 ),
65 (
66 "splunk://%badroute%@apikey",
67 {
68 "instance": TypeError,
69 },
70 ),
71 (
72 "splunk://?apikey=abc123&routing_key=db",
73 {
74 # We're good
75 "instance": NotifySplunk,
76 },
77 ),
78 (
79 "splunk://route@abc123/entity_id",
80 {
81 # We're good
82 "instance": NotifySplunk,
83 },
84 ),
85 (
86 "splunk://route@abc123/?entity_id=my_entity",
87 {
88 # We're good
89 "instance": NotifySplunk,
90 },
91 ),
92 (
93 # An entity_id containing characters that are reserved in a URL
94 # (?, #, %, /) must survive a url() round-trip without being
95 # truncated or corrupted.
96 "splunk://route@abc123/?entity_id=a%3Fb%23c%25d%2Fe",
97 {
98 # We're good
99 "instance": NotifySplunk,
100 # Our privacy url confirms the entity_id was quoted (not
101 # dropped) when the url() was re-assembled
102 "privacy_url": "splunk://[email protected]/a%3Fb%23c%25d/e",
103 },
104 ),
105 # Support legacy URL
106 (
107 (
108 "https://alert.victorops.com/integrations/generic/20131114/"
109 "alert/apikey/routing_key"
110 ),
111 {
112 # We're good
113 "instance": NotifySplunk,
114 },
115 ),
116 # Support legacy URL (with entity id provided)
117 (
118 (
119 "https://alert.victorops.com/integrations/generic/20131114/"
120 "alert/apikey/routing_key/entity_id"
121 ),
122 {
123 # We're good
124 "instance": NotifySplunk,
125 },
126 ),
127 # support victorops:// too!
128 (
129 "victorops://?apikey=abc123&route=db",
130 {
131 # We're good
132 "instance": NotifySplunk,
133 },
134 ),
135 (
136 "splunk://?apikey=abc123&route=db",
137 {
138 # We're good
139 "instance": NotifySplunk,
140 },
141 ),
142 (
143 "splunk://db@apikey?action=recovery",
144 {
145 # Always Recovery Alias
146 "instance": NotifySplunk,
147 },
148 ),
149 (
150 "splunk://db@apikey?action=resolve",
151 {
152 # Always Recovery Alias
153 "instance": NotifySplunk,
154 },
155 ),
156 (
157 "splunk://db@apikey?action=r",
158 {
159 # Always Recovery (short form)
160 "instance": NotifySplunk,
161 },
162 ),
163 (
164 "splunk://db@apikey?action=acknowledgement",
165 {
166 # Always Acknowledgement
167 "instance": NotifySplunk,
168 },
169 ),
170 (
171 "splunk://db@apikey?action=ack",
172 {
173 # Always Acknowledgement (short form)
174 "instance": NotifySplunk,
175 },
176 ),
177 (
178 "splunk://db@apikey?action=critical",
179 {
180 # Always Critical
181 "instance": NotifySplunk,
182 },
183 ),
184 (
185 "splunk://db@apikey?action=crit",
186 {
187 # Always Critical (short form)
188 "instance": NotifySplunk,
189 },
190 ),
191 (
192 "splunk://db@apikey?action=warning",
193 {
194 # Always Warning
195 "instance": NotifySplunk,
196 },
197 ),
198 (
199 "splunk://db@apikey?action=warn",
200 {
201 # Always Warning (short form)
202 "instance": NotifySplunk,
203 },
204 ),
205 (
206 "splunk://db@apikey?action=info",
207 {
208 # Always INFO
209 "instance": NotifySplunk,
210 },
211 ),
212 (
213 "splunk://db@apikey?action=i",
214 {
215 # Always INFO (short form)
216 "instance": NotifySplunk,
217 },
218 ),
219 (
220 "splunk://db@apikey?action=invalid",
221 {
222 # Invalid Action
223 "instance": TypeError,
224 },
225 ),
226 (
227 "splunk://db@apikey?:warning=critical",
228 {
229 # Map warnings to CRITICAL
230 "instance": NotifySplunk,
231 },
232 ),
233 (
234 "splunk://db@apikey?:invalid=critical",
235 {
236 # A bad Apprise Notification Type was provided
237 "instance": TypeError,
238 },
239 ),
240 (
241 "splunk://db@apikey?:warning=invalid",
242 {
243 # A bad Splunk Notification Type was provided
244 "instance": TypeError,
245 },
246 ),
247 (
248 "splunk://db@apikey",
249 {
250 "instance": NotifySplunk,
251 # force a failure
252 "response": False,
253 "requests_response_code": requests.codes.internal_server_error,
254 },
255 ),
256 (
257 "splunk://db@apikey",
258 {
259 "instance": NotifySplunk,
260 # throw a bizarre code forcing us to fail to look it up
261 "response": False,
262 "requests_response_code": 999,
263 },
264 ),
265 (
266 "splunk://db@token",
267 {
268 "instance": NotifySplunk,
269 # Throws a series of i/o exceptions with this flag
270 # is set and tests that we gracefully handle them
271 "test_requests_exceptions": True,
272 },
273 ),
274 )
275
276
277 def test_plugin_splunk_urls():
278 """NotifySplunk() Apprise URLs."""
279
280 # Run our general tests
281 AppriseURLTester(tests=apprise_url_tests).run_all()