Debian Codegraph @

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