Debian Codegraph @

tests/test_plugin_pushy.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
33 from apprise.plugins.pushy import NotifyPushy
34
35 logging.disable(logging.CRITICAL)
36
37
38 # However we'll be okay if we return a proper response
39 GOOD_RESPONSE = {
40 "success": True,
41 }
42
43 # Our Testing URLs
44 apprise_url_tests = (
45 (
46 "pushy://",
47 {
48 # No no secret api key
49 "instance": TypeError,
50 },
51 ),
52 (
53 "pushy://:@/",
54 {
55 # just invalid all around
56 "instance": TypeError,
57 },
58 ),
59 (
60 "pushy://apikey",
61 {
62 # No Device/Topic specified
63 "instance": NotifyPushy,
64 # Expected notify() response False (because we won't be able
65 # to actually notify anything if no device_key was specified
66 "notify_response": False,
67 "requests_response_text": GOOD_RESPONSE,
68 },
69 ),
70 (
71 "pushy://apikey/topic",
72 {
73 # No Device/Topic specified
74 "instance": NotifyPushy,
75 # Expected notify() response False because the success flag
76 # was set to false
77 "notify_response": False,
78 "requests_response_text": {"success": False},
79 },
80 ),
81 (
82 "pushy://apikey/topic",
83 {
84 # No Device/Topic specified
85 "instance": NotifyPushy,
86 # Expected notify() response False because the success flag
87 # was set to false
88 "notify_response": False,
89 # Invalid JSON data
90 "requests_response_text": "}",
91 },
92 ),
93 (
94 "pushy://apikey/%20(",
95 {
96 # Invalid topic specified
97 "instance": NotifyPushy,
98 # Expected notify() response False because there is no one to
99 # notify
100 "notify_response": False,
101 "requests_response_text": GOOD_RESPONSE,
102 },
103 ),
104 (
105 "pushy://apikey/@device",
106 {
107 # Everything is okay
108 "instance": NotifyPushy,
109 "requests_response_text": GOOD_RESPONSE,
110 # Our expected url(privacy=True) startswith() response:
111 "privacy_url": "pushy://a...y/@device/",
112 },
113 ),
114 (
115 "pushy://apikey/topic",
116 {
117 # Everything is okay; no prefix means it's a topic
118 "instance": NotifyPushy,
119 "requests_response_text": GOOD_RESPONSE,
120 # Our expected url(privacy=True) startswith() response:
121 "privacy_url": "pushy://a...y/#topic/",
122 },
123 ),
124 (
125 "pushy://apikey/device/?sound=alarm.aiff",
126 {
127 # alarm.aiff sound loaded
128 "instance": NotifyPushy,
129 "requests_response_text": GOOD_RESPONSE,
130 },
131 ),
132 (
133 "pushy://apikey/device/?badge=100",
134 {
135 # set badge
136 "instance": NotifyPushy,
137 "requests_response_text": GOOD_RESPONSE,
138 },
139 ),
140 (
141 "pushy://apikey/device/?badge=invalid",
142 {
143 # set invalid badge
144 "instance": NotifyPushy,
145 "requests_response_text": GOOD_RESPONSE,
146 },
147 ),
148 (
149 "pushy://apikey/device/?badge=-12",
150 {
151 # set invalid badge
152 "instance": NotifyPushy,
153 "requests_response_text": GOOD_RESPONSE,
154 },
155 ),
156 (
157 "pushy://_/@device/#topic?key=apikey",
158 {
159 # set device and topic
160 "instance": NotifyPushy,
161 "requests_response_text": GOOD_RESPONSE,
162 },
163 ),
164 (
165 "pushy://apikey/?to=@device",
166 {
167 # test use of to= argument
168 "instance": NotifyPushy,
169 "requests_response_text": GOOD_RESPONSE,
170 },
171 ),
172 (
173 "pushy://_/@device/#topic?key=apikey",
174 {
175 "instance": NotifyPushy,
176 # throw a bizarre code forcing us to fail to look it up
177 "response": False,
178 "requests_response_code": 999,
179 "requests_response_text": GOOD_RESPONSE,
180 # Our expected url(privacy=True) startswith() response:
181 "privacy_url": "pushy://a...y/#topic/@device/",
182 },
183 ),
184 (
185 "pushy://_/@device/#topic?key=apikey",
186 {
187 "instance": NotifyPushy,
188 "requests_response_text": GOOD_RESPONSE,
189 # Throws a series of i/o exceptions with this flag
190 # is set and tests that we gracefully handle them
191 "test_requests_exceptions": True,
192 },
193 ),
194 )
195
196
197 def test_plugin_pushy_urls():
198 """NotifyPushy() Apprise URLs."""
199
200 # Run our general tests
201 AppriseURLTester(tests=apprise_url_tests).run_all()