Debian Codegraph @

tests/test_plugin_flock.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.flock import NotifyFlock
37
38 logging.disable(logging.CRITICAL)
39
40 # Our Testing URLs
41 apprise_url_tests = (
42 (
43 "flock://",
44 {
45 "instance": TypeError,
46 },
47 ),
48 # An invalid url
49 (
50 "flock://:@/",
51 {
52 "instance": TypeError,
53 },
54 ),
55 # Provide a token
56 (
57 "flock://%s" % ("t" * 24),
58 {
59 "instance": NotifyFlock,
60 },
61 ),
62 # Image handling
63 (
64 "flock://%s?image=True" % ("t" * 24),
65 {
66 "instance": NotifyFlock,
67 # Our expected url(privacy=True) startswith() response:
68 "privacy_url": "flock://t...t",
69 },
70 ),
71 (
72 "flock://%s?image=False" % ("t" * 24),
73 {
74 "instance": NotifyFlock,
75 },
76 ),
77 (
78 "flock://%s?image=True" % ("t" * 24),
79 {
80 "instance": NotifyFlock,
81 # Run test when image is set to True, but one couldn't actually be
82 # loaded from the Asset Object.
83 "include_image": False,
84 },
85 ),
86 # Test to=
87 (
88 "flock://{}?to=u:{}&format=markdown".format("i" * 24, "u" * 12),
89 {
90 "instance": NotifyFlock,
91 },
92 ),
93 # Provide markdown format
94 (
95 "flock://%s?format=markdown" % ("i" * 24),
96 {
97 "instance": NotifyFlock,
98 },
99 ),
100 # Provide text format
101 (
102 "flock://%s?format=text" % ("i" * 24),
103 {
104 "instance": NotifyFlock,
105 },
106 ),
107 # Native URL Support, take the slack URL and still build from it
108 (
109 "https://api.flock.com/hooks/sendMessage/{}/".format("i" * 24),
110 {
111 "instance": NotifyFlock,
112 },
113 ),
114 # Native URL Support with arguments
115 (
116 "https://api.flock.com/hooks/sendMessage/{}/?format=markdown".format(
117 "i" * 24
118 ),
119 {
120 "instance": NotifyFlock,
121 },
122 ),
123 # Bot API presumed if one or more targets are specified
124 # Provide markdown format
125 (
126 "flock://{}/u:{}?format=markdown".format("i" * 24, "u" * 12),
127 {
128 "instance": NotifyFlock,
129 },
130 ),
131 # Bot API presumed if one or more targets are specified
132 # Provide text format
133 (
134 "flock://{}/u:{}?format=html".format("i" * 24, "u" * 12),
135 {
136 "instance": NotifyFlock,
137 },
138 ),
139 # Bot API presumed if one or more targets are specified
140 # u: is optional
141 (
142 "flock://{}/{}?format=text".format("i" * 24, "u" * 12),
143 {
144 "instance": NotifyFlock,
145 },
146 ),
147 # Bot API presumed if one or more targets are specified
148 # Multi-entries
149 (
150 "flock://{}/g:{}/u:{}?format=text".format(
151 "i" * 24, "g" * 12, "u" * 12
152 ),
153 {
154 "instance": NotifyFlock,
155 },
156 ),
157 # Bot API presumed if one or more targets are specified
158 # Multi-entries using @ for user and # for channel
159 (
160 "flock://{}/#{}/@{}?format=text".format("i" * 24, "g" * 12, "u" * 12),
161 {
162 "instance": NotifyFlock,
163 },
164 ),
165 # Bot API presumed if one or more targets are specified
166 # has bad entry
167 (
168 "flock://{}/g:{}/u:{}?format=text".format(
169 "i" * 24, "g" * 12, "u" * 10
170 ),
171 {
172 "instance": NotifyFlock,
173 },
174 ),
175 # Invalid user/group defined
176 (
177 "flock://%s/g:/u:?format=text" % ("i" * 24),
178 {
179 "instance": TypeError,
180 },
181 ),
182 # we don't focus on the invalid length of the user/group fields.
183 # As a result, the following will load and pass the data upstream
184 (
185 "flock://{}/g:{}/u:{}?format=text".format(
186 "i" * 24, "g" * 14, "u" * 10
187 ),
188 {
189 # We will still instantiate the object
190 "instance": NotifyFlock,
191 },
192 ),
193 # Error Testing
194 (
195 "flock://{}/g:{}/u:{}?format=text".format(
196 "i" * 24, "g" * 12, "u" * 10
197 ),
198 {
199 "instance": NotifyFlock,
200 # force a failure
201 "response": False,
202 "requests_response_code": requests.codes.internal_server_error,
203 },
204 ),
205 (
206 "flock://%s/" % ("t" * 24),
207 {
208 "instance": NotifyFlock,
209 # force a failure
210 "response": False,
211 "requests_response_code": requests.codes.internal_server_error,
212 },
213 ),
214 (
215 "flock://%s/" % ("t" * 24),
216 {
217 "instance": NotifyFlock,
218 # throw a bizarre code forcing us to fail to look it up
219 "response": False,
220 "requests_response_code": 999,
221 },
222 ),
223 (
224 "flock://%s/" % ("t" * 24),
225 {
226 "instance": NotifyFlock,
227 # Throws a series of i/o exceptions with this flag
228 # is set and tests that we gracefully handle them
229 "test_requests_exceptions": True,
230 },
231 ),
232 )
233
234
235 def test_plugin_flock_urls():
236 """NotifyFlock() Apprise URLs."""
237
238 # Run our general tests
239 AppriseURLTester(tests=apprise_url_tests).run_all()
240
241
242 @mock.patch("requests.get")
243 @mock.patch("requests.post")
244 def test_plugin_flock_edge_cases(mock_post, mock_get):
245 """NotifyFlock() Edge Cases."""
246
247 # Initializes the plugin with an invalid token
248 with pytest.raises(TypeError):
249 NotifyFlock(token=None)
250 # Whitespace also acts as an invalid token value
251 with pytest.raises(TypeError):
252 NotifyFlock(token=" ")