| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
from json import dumps |
| 29 |
|
| 30 |
|
| 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 |
|
| 43 |
apprise_url_tests = ( |
| 44 |
( |
| 45 |
"burstsms://", |
| 46 |
{ |
| 47 |
|
| 48 |
"instance": TypeError, |
| 49 |
}, |
| 50 |
), |
| 51 |
( |
| 52 |
"burstsms://:@/", |
| 53 |
{ |
| 54 |
|
| 55 |
"instance": TypeError, |
| 56 |
}, |
| 57 |
), |
| 58 |
( |
| 59 |
"burstsms://{}@12345678".format("a" * 8), |
| 60 |
{ |
| 61 |
|
| 62 |
"instance": TypeError, |
| 63 |
}, |
| 64 |
), |
| 65 |
( |
| 66 |
"burstsms://{}:{}@%20".format("d" * 8, "e" * 16), |
| 67 |
{ |
| 68 |
|
| 69 |
"instance": TypeError, |
| 70 |
}, |
| 71 |
), |
| 72 |
( |
| 73 |
"burstsms://{}:{}@{}/123/{}/abcd/".format( |
| 74 |
"f" * 8, "g" * 16, "3" * 11, "9" * 15 |
| 75 |
), |
| 76 |
{ |
| 77 |
|
| 78 |
"instance": NotifyBurstSMS, |
| 79 |
|
| 80 |
"notify_response": False, |
| 81 |
|
| 82 |
"privacy_url": "burstsms://f...f:****@", |
| 83 |
}, |
| 84 |
), |
| 85 |
( |
| 86 |
"burstsms://{}:{}@{}".format("h" * 8, "i" * 16, "5" * 11), |
| 87 |
{ |
| 88 |
"instance": NotifyBurstSMS, |
| 89 |
|
| 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 |
|
| 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 |
|
| 108 |
"instance": NotifyBurstSMS, |
| 109 |
}, |
| 110 |
), |
| 111 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 153 |
"instance": NotifyBurstSMS, |
| 154 |
}, |
| 155 |
), |
| 156 |
( |
| 157 |
"burstsms://{}:{}@{}/{}".format("a" * 8, "b" * 16, "6" * 11, "7" * 11), |
| 158 |
{ |
| 159 |
"instance": NotifyBurstSMS, |
| 160 |
|
| 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 |
|
| 170 |
|
| 171 |
"test_requests_exceptions": True, |
| 172 |
}, |
| 173 |
), |
| 174 |
) |
| 175 |
|
| 176 |
|
| 177 |
def test_plugin_burstsms_urls(): |
| 178 |
"""NotifyBurstSMS() Apprise URLs.""" |
| 179 |
|
| 180 |
|
| 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 |
|
| 189 |
response = requests.Request() |
| 190 |
response.status_code = requests.codes.ok |
| 191 |
|
| 192 |
|
| 193 |
mock_post.return_value = response |
| 194 |
|
| 195 |
|
| 196 |
apikey = "{}".format("b" * 8) |
| 197 |
secret = "{}".format("b" * 16) |
| 198 |
source = "+1 (555) 123-3456" |
| 199 |
|
| 200 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 230 |
obj = NotifyBurstSMS(apikey=apikey, secret=secret, source=source) |
| 231 |
|
| 232 |
|
| 233 |
assert obj.notify("title", "body", "info") is False |