| 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 |
from json import dumps |
| 29 |
import logging |
| 30 |
from unittest import mock |
| 31 |
|
| 32 |
from helpers import AppriseURLTester |
| 33 |
import pytest |
| 34 |
import requests |
| 35 |
|
| 36 |
from apprise.exception import AppriseImproperlyConfigured |
| 37 |
from apprise.plugins.clickatell import NotifyClickatell |
| 38 |
|
| 39 |
logging.disable(logging.CRITICAL) |
| 40 |
|
| 41 |
# Our Testing URLs |
| 42 |
apprise_url_tests = ( |
| 43 |
( |
| 44 |
"clickatell://", |
| 45 |
{ |
| 46 |
# only schema provided |
| 47 |
"instance": AppriseImproperlyConfigured, |
| 48 |
}, |
| 49 |
), |
| 50 |
( |
| 51 |
"clickatell:///", |
| 52 |
{ |
| 53 |
# invalid apikey |
| 54 |
"instance": AppriseImproperlyConfigured, |
| 55 |
}, |
| 56 |
), |
| 57 |
( |
| 58 |
"clickatell://@/", |
| 59 |
{ |
| 60 |
# invalid apikey |
| 61 |
"instance": AppriseImproperlyConfigured, |
| 62 |
}, |
| 63 |
), |
| 64 |
( |
| 65 |
"clickatell://{}@/".format("1" * 10), |
| 66 |
{ |
| 67 |
# no api key provided |
| 68 |
"instance": AppriseImproperlyConfigured, |
| 69 |
}, |
| 70 |
), |
| 71 |
( |
| 72 |
"clickatell://{}@{}/".format("1" * 3, "a" * 32), |
| 73 |
{ |
| 74 |
# invalid From/Source |
| 75 |
"instance": AppriseImproperlyConfigured |
| 76 |
}, |
| 77 |
), |
| 78 |
( |
| 79 |
"clickatell://{}/".format("a" * 32), |
| 80 |
{ |
| 81 |
# no targets provided |
| 82 |
"instance": NotifyClickatell, |
| 83 |
# We have no one to notify |
| 84 |
"notify_response": False, |
| 85 |
}, |
| 86 |
), |
| 87 |
( |
| 88 |
"clickatell://{}@{}/".format("1" * 10, "a" * 32), |
| 89 |
{ |
| 90 |
# no targets provided (no one to notify) |
| 91 |
"instance": NotifyClickatell, |
| 92 |
# We have no one to notify |
| 93 |
"notify_response": False, |
| 94 |
}, |
| 95 |
), |
| 96 |
( |
| 97 |
"clickatell://{}@{}/123/{}/abcd".format("1" * 10, "a" * 32, "3" * 15), |
| 98 |
{ |
| 99 |
# valid everything but target numbers |
| 100 |
"instance": NotifyClickatell, |
| 101 |
# We have no one to notify |
| 102 |
"notify_response": False, |
| 103 |
}, |
| 104 |
), |
| 105 |
( |
| 106 |
"clickatell://{}/{}".format("1" * 10, "a" * 32), |
| 107 |
{ |
| 108 |
# everything valid (no source defined) |
| 109 |
"instance": NotifyClickatell, |
| 110 |
# We have no one to notify |
| 111 |
"notify_response": False, |
| 112 |
}, |
| 113 |
), |
| 114 |
( |
| 115 |
"clickatell://{}@{}/{}".format("1" * 10, "a" * 32, "1" * 10), |
| 116 |
{ |
| 117 |
# everything valid |
| 118 |
"instance": NotifyClickatell, |
| 119 |
}, |
| 120 |
), |
| 121 |
( |
| 122 |
"clickatell://{}/{}".format("a" * 32, "1" * 10), |
| 123 |
{ |
| 124 |
# everything valid (no source) |
| 125 |
"instance": NotifyClickatell, |
| 126 |
}, |
| 127 |
), |
| 128 |
( |
| 129 |
"clickatell://_?apikey={}&from={}&to={},{}".format( |
| 130 |
"a" * 32, "1" * 10, "1" * 10, "1" * 10 |
| 131 |
), |
| 132 |
{ |
| 133 |
# use get args to accomplish the same thing |
| 134 |
"instance": NotifyClickatell, |
| 135 |
}, |
| 136 |
), |
| 137 |
( |
| 138 |
"clickatell://_?apikey={}".format("a" * 32), |
| 139 |
{ |
| 140 |
# use get args |
| 141 |
"instance": NotifyClickatell, |
| 142 |
"notify_response": False, |
| 143 |
}, |
| 144 |
), |
| 145 |
( |
| 146 |
"clickatell://_?apikey={}&from={}".format("a" * 32, "1" * 10), |
| 147 |
{ |
| 148 |
# use get args |
| 149 |
"instance": NotifyClickatell, |
| 150 |
"notify_response": False, |
| 151 |
}, |
| 152 |
), |
| 153 |
( |
| 154 |
"clickatell://{}@{}/{}".format("1" * 10, "a" * 32, "1" * 10), |
| 155 |
{ |
| 156 |
"instance": NotifyClickatell, |
| 157 |
# throw a bizarre code forcing us to fail to look it up |
| 158 |
"response": False, |
| 159 |
"requests_response_code": 999, |
| 160 |
}, |
| 161 |
), |
| 162 |
( |
| 163 |
"clickatell://{}@{}/{}".format("1" * 10, "a" * 32, "1" * 10), |
| 164 |
{ |
| 165 |
"instance": NotifyClickatell, |
| 166 |
# Throws a series of i/o exceptions with this flag |
| 167 |
# is set and tests that we gracefully handle them |
| 168 |
"test_requests_exceptions": True, |
| 169 |
}, |
| 170 |
), |
| 171 |
) |
| 172 |
|
| 173 |
|
| 174 |
def test_plugin_clickatell_urls(): |
| 175 |
"""NotifyClickatell() Apprise URLs.""" |
| 176 |
|
| 177 |
# Run our general tests |
| 178 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 179 |
|
| 180 |
|
| 181 |
@mock.patch("requests.post") |
| 182 |
def test_plugin_clickatell_edge_cases(mock_post): |
| 183 |
"""NotifyClickatell() Edge Cases.""" |
| 184 |
|
| 185 |
# Prepare our response |
| 186 |
response = requests.Request() |
| 187 |
response.status_code = requests.codes.ok |
| 188 |
|
| 189 |
# Prepare Mock |
| 190 |
mock_post.return_value = response |
| 191 |
|
| 192 |
# Initialize some generic (but valid) apikeys |
| 193 |
apikey = "b" * 32 |
| 194 |
from_phone = "+1 (555) 123-3456" |
| 195 |
|
| 196 |
# No apikey specified |
| 197 |
with pytest.raises(AppriseImproperlyConfigured): |
| 198 |
NotifyClickatell(apikey=None, from_phone=from_phone) |
| 199 |
|
| 200 |
# a error response |
| 201 |
response.status_code = 400 |
| 202 |
response.content = dumps( |
| 203 |
{ |
| 204 |
"code": 21211, |
| 205 |
"message": "The 'To' number +1234567 is not a valid phone number.", |
| 206 |
} |
| 207 |
) |
| 208 |
mock_post.return_value = response |
| 209 |
|
| 210 |
# Initialize our object |
| 211 |
obj = NotifyClickatell(apikey=apikey, from_phone=from_phone) |
| 212 |
|
| 213 |
# We will fail with the above error code |
| 214 |
assert bool(obj.notify("title", "body", "info")) is False |