Debian Codegraph @

tests/test_plugin_burstsms.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
30 # Disable logging for a cleaner testing output
31 import logging
32 from unittest import mock
33
34 from helpers import AppriseURLTester
35 import pytest
36 import requests
37
38 from apprise.plugins.burstsms import NotifyBurstSMS
39
40 logging.disable(logging.CRITICAL)
41
42 # Our Testing URLs
43 apprise_url_tests = (
44 (
45 "burstsms://",
46 {
47 # No API Key specified
48 "instance": TypeError,
49 },
50 ),
51 (
52 "burstsms://:@/",
53 {
54 # invalid Auth key
55 "instance": TypeError,
56 },
57 ),
58 (
59 "burstsms://{}@12345678".format("a" * 8),
60 {
61 # Just a key provided
62 "instance": TypeError,
63 },
64 ),
65 (
66 "burstsms://{}:{}@%20".format("d" * 8, "e" * 16),
67 {
68 # Invalid source number
69 "instance": TypeError,
70 },
71 ),
72 (
73 "burstsms://{}:{}@{}/123/{}/abcd/".format(
74 "f" * 8, "g" * 16, "3" * 11, "9" * 15
75 ),
76 {
77 # valid everything but target numbers
78 "instance": NotifyBurstSMS,
79 # Expected notify() response because not all targets are valid
80 "notify_response": False,
81 # Our expected url(privacy=True) startswith() response:
82 "privacy_url": "burstsms://f...f:****@",
83 },
84 ),
85 (
86 "burstsms://{}:{}@{}".format("h" * 8, "i" * 16, "5" * 11),
87 {
88 "instance": NotifyBurstSMS,
89 # Expected notify() response because no targets are defined
90 "notify_response": False,
91 },
92 ),
93 (
94 "burstsms://_?key={}&secret={}&from={}&to={}".format(
95 "a" * 8, "b" * 16, "5" * 11, "6" * 11
96 ),
97 {
98 # use get args to acomplish the same thing
99 "instance": NotifyBurstSMS,
100 },
101 ),
102 (
103 "burstsms://_?key={}&secret={}&from={}&to={}&batch=y".format(
104 "a" * 8, "b" * 16, "5" * 11, "6" * 11
105 ),
106 {
107 # batch flag set
108 "instance": NotifyBurstSMS,
109 },
110 ),
111 # Test our country
112 (
113 "burstsms://_?key={}&secret={}&source={}&to={}&country=us".format(
114 "a" * 8, "b" * 16, "5" * 11, "6" * 11
115 ),
116 {
117 "instance": NotifyBurstSMS,
118 },
119 ),
120 # Test an invalid country
121 (
122 "burstsms://_?key={}&secret={}&source={}&to={}&country=invalid".format(
123 "a" * 8, "b" * 16, "5" * 11, "6" * 11
124 ),
125 {
126 "instance": TypeError,
127 },
128 ),
129 # Test our validity
130 (
131 "burstsms://_?key={}&secret={}&source={}&to={}&validity=10".format(
132 "a" * 8, "b" * 16, "5" * 11, "6" * 11
133 ),
134 {
135 "instance": NotifyBurstSMS,
136 },
137 ),
138 # Test an invalid country
139 (
140 "burstsms://_?key={}&secret={}&source={}&to={}&validity=invalid".format(
141 "a" * 8, "b" * 16, "5" * 11, "6" * 11
142 ),
143 {
144 "instance": TypeError,
145 },
146 ),
147 (
148 "burstsms://_?key={}&secret={}&from={}&to={}".format(
149 "a" * 8, "b" * 16, "5" * 11, "7" * 11
150 ),
151 {
152 # use to=
153 "instance": NotifyBurstSMS,
154 },
155 ),
156 (
157 "burstsms://{}:{}@{}/{}".format("a" * 8, "b" * 16, "6" * 11, "7" * 11),
158 {
159 "instance": NotifyBurstSMS,
160 # throw a bizarre code forcing us to fail to look it up
161 "response": False,
162 "requests_response_code": 999,
163 },
164 ),
165 (
166 "burstsms://{}:{}@{}/{}".format("a" * 8, "b" * 16, "6" * 11, "7" * 11),
167 {
168 "instance": NotifyBurstSMS,
169 # Throws a series of i/o exceptions with this flag
170 # is set and tests that we gracefully handle them
171 "test_requests_exceptions": True,
172 },
173 ),
174 )
175
176
177 def test_plugin_burstsms_urls():
178 """NotifyBurstSMS() Apprise URLs."""
179
180 # Run our general tests
181 AppriseURLTester(tests=apprise_url_tests).run_all()
182
183
184 @mock.patch("requests.post")
185 def test_plugin_burstsms_edge_cases(mock_post):
186 """NotifyBurstSMS() Edge Cases."""
187
188 # Prepare our response
189 response = requests.Request()
190 response.status_code = requests.codes.ok
191
192 # Prepare Mock
193 mock_post.return_value = response
194
195 # Initialize some generic (but valid) tokens
196 apikey = "{}".format("b" * 8)
197 secret = "{}".format("b" * 16)
198 source = "+1 (555) 123-3456"
199
200 # No apikey specified
201 with pytest.raises(TypeError):
202 NotifyBurstSMS(apikey=None, secret=secret, source=source)
203
204 with pytest.raises(TypeError):
205 NotifyBurstSMS(apikey=" ", secret=secret, source=source)
206
207 # No secret specified
208 with pytest.raises(TypeError):
209 NotifyBurstSMS(apikey=apikey, secret=None, source=source)
210
211 with pytest.raises(TypeError):
212 NotifyBurstSMS(apikey=apikey, secret=" ", source=source)
213
214 # a error response
215 response.status_code = 400
216 response.content = dumps(
217 {
218 "error": {
219 "code": "FIELD_INVALID",
220 "description": (
221 "Sender ID must be one of the numbers that are currently"
222 " leased."
223 ),
224 },
225 }
226 )
227 mock_post.return_value = response
228
229 # Initialize our object
230 obj = NotifyBurstSMS(apikey=apikey, secret=secret, source=source)
231
232 # We will fail with the above error code
233 assert obj.notify("title", "body", "info") is False