Debian Codegraph @

tests/test_plugin_synology.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 requests
34
35 from apprise.plugins.synology import NotifySynology
36
37 logging.disable(logging.CRITICAL)
38
39 # Our Testing URLs
40 apprise_url_tests = (
41 (
42 "synology://:@/",
43 {
44 "instance": None,
45 },
46 ),
47 (
48 "synology://",
49 {
50 "instance": None,
51 },
52 ),
53 (
54 "synologys://",
55 {
56 "instance": None,
57 },
58 ),
59 (
60 "synology://localhost/token",
61 {
62 "instance": NotifySynology,
63 },
64 ),
65 (
66 "synology://localhost/token?file_url=http://reddit.com/test.jpg",
67 {
68 "instance": NotifySynology,
69 },
70 ),
71 (
72 "synology://user:pass@localhost/token",
73 {
74 "instance": NotifySynology,
75 # Our expected url(privacy=True) startswith() response:
76 "privacy_url": "synology://user:****@localhost/t...n",
77 },
78 ),
79 # No token was specified
80 (
81 "synology://user@localhost",
82 {
83 "instance": TypeError,
84 },
85 ),
86 (
87 "synology://user@localhost/token",
88 {
89 "instance": NotifySynology,
90 },
91 ),
92 # Continue testing other cases
93 (
94 "synology://localhost:8080/token",
95 {
96 "instance": NotifySynology,
97 },
98 ),
99 (
100 "synology://user:pass@localhost:8080/token",
101 {
102 "instance": NotifySynology,
103 },
104 ),
105 (
106 "synologys://localhost/token",
107 {
108 "instance": NotifySynology,
109 },
110 ),
111 (
112 "synologys://localhost/?token=mytoken",
113 {
114 "instance": NotifySynology,
115 # Our expected url(privacy=True) startswith() response:
116 "privacy_url": "synologys://localhost/m...n",
117 },
118 ),
119 (
120 "synologys://user:pass@localhost/token",
121 {
122 "instance": NotifySynology,
123 },
124 ),
125 (
126 "synologys://localhost:8080/token/path/",
127 {
128 "instance": NotifySynology,
129 # Our expected url(privacy=True) startswith() response:
130 "privacy_url": "synologys://localhost:8080/t...n/path/",
131 },
132 ),
133 (
134 "synologys://user:password@localhost:8080/token",
135 {
136 "instance": NotifySynology,
137 # Our expected url(privacy=True) startswith() response:
138 "privacy_url": "synologys://user:****@localhost:8080/t...n",
139 },
140 ),
141 # Test our Headers
142 (
143 "synology://localhost:8080/path?+HeaderKey=HeaderValue",
144 {
145 "instance": NotifySynology,
146 },
147 ),
148 (
149 "synology://user:pass@localhost:8081/token",
150 {
151 "instance": NotifySynology,
152 # force a failure
153 "response": False,
154 "requests_response_code": requests.codes.internal_server_error,
155 },
156 ),
157 (
158 "synology://user:pass@localhost:8082/token",
159 {
160 "instance": NotifySynology,
161 # throw a bizarre code forcing us to fail to look it up
162 "response": False,
163 "requests_response_code": 999,
164 },
165 ),
166 (
167 "synology://user:pass@localhost:8083/token",
168 {
169 "instance": NotifySynology,
170 # Throws a series of i/o exceptions with this flag
171 # is set and tests that we gracefully handle them
172 "test_requests_exceptions": True,
173 },
174 ),
175 )
176
177
178 def test_plugin_custom_synology_urls():
179 """NotifySynology() Apprise URLs."""
180
181 # Run our general tests
182 AppriseURLTester(tests=apprise_url_tests).run_all()
183
184
185 @mock.patch("requests.post")
186 def test_plugin_synology_edge_cases(mock_post):
187 """NotifySynology() Edge Cases."""
188
189 # Prepare our response
190 response = requests.Request()
191 response.status_code = requests.codes.ok
192
193 # Prepare Mock
194 mock_post.return_value = response
195
196 # This string also tests that type is set to nothing
197 results = NotifySynology.parse_url(
198 "synology://user:pass@localhost:8080/token"
199 )
200
201 assert isinstance(results, dict)
202 assert results["user"] == "user"
203 assert results["password"] == "pass"
204 assert results["port"] == 8080
205 assert results["host"] == "localhost"
206 assert results["fullpath"] == ""
207 assert results["path"] == "/"
208 assert results["query"] == "token"
209 assert results["schema"] == "synology"
210 assert results["url"] == "synology://user:pass@localhost:8080/token"
211
212 instance = NotifySynology(**results)
213 assert isinstance(instance, NotifySynology)
214
215 response = instance.send(title="title", body="body")
216 assert response is True
217 assert mock_post.call_count == 1
218
219 details = mock_post.call_args_list[0]
220 assert details[0][0] == "http://localhost:8080/webapi/entry.cgi"
221
222 assert details[1]["data"].startswith("payload=")