Debian Codegraph @

tests/test_plugin_pushy.py

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