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