| 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.vonage import NotifyVonage |
| 39 |
|
| 40 |
logging.disable(logging.CRITICAL) |
| 41 |
|
| 42 |
|
| 43 |
apprise_url_tests = ( |
| 44 |
( |
| 45 |
"vonage://", |
| 46 |
{ |
| 47 |
|
| 48 |
"instance": TypeError, |
| 49 |
}, |
| 50 |
), |
| 51 |
( |
| 52 |
"vonage://:@/", |
| 53 |
{ |
| 54 |
|
| 55 |
"instance": TypeError, |
| 56 |
}, |
| 57 |
), |
| 58 |
( |
| 59 |
"vonage://AC{}@12345678".format("a" * 8), |
| 60 |
{ |
| 61 |
|
| 62 |
"instance": TypeError, |
| 63 |
}, |
| 64 |
), |
| 65 |
( |
| 66 |
"vonage://AC{}:{}@{}".format("a" * 8, "b" * 16, "3" * 9), |
| 67 |
{ |
| 68 |
|
| 69 |
"instance": TypeError, |
| 70 |
}, |
| 71 |
), |
| 72 |
( |
| 73 |
"vonage://AC{}:{}@{}/?ttl=0".format("b" * 8, "c" * 16, "3" * 11), |
| 74 |
{ |
| 75 |
|
| 76 |
"instance": TypeError, |
| 77 |
}, |
| 78 |
), |
| 79 |
( |
| 80 |
"vonage://AC{}:{}@{}".format("d" * 8, "e" * 16, "a" * 11), |
| 81 |
{ |
| 82 |
|
| 83 |
"instance": TypeError, |
| 84 |
}, |
| 85 |
), |
| 86 |
( |
| 87 |
"vonage://AC{}:{}@{}/123/{}/abcd/".format( |
| 88 |
"f" * 8, "g" * 16, "3" * 11, "9" * 15 |
| 89 |
), |
| 90 |
{ |
| 91 |
|
| 92 |
"instance": NotifyVonage, |
| 93 |
|
| 94 |
"privacy_url": "vonage://A...f:****@", |
| 95 |
}, |
| 96 |
), |
| 97 |
( |
| 98 |
"vonage://AC{}:{}@{}".format("h" * 8, "i" * 16, "5" * 11), |
| 99 |
{ |
| 100 |
|
| 101 |
|
| 102 |
"instance": NotifyVonage, |
| 103 |
}, |
| 104 |
), |
| 105 |
( |
| 106 |
"vonage://_?key=AC{}&secret={}&from={}".format( |
| 107 |
"a" * 8, "b" * 16, "5" * 11 |
| 108 |
), |
| 109 |
{ |
| 110 |
|
| 111 |
"instance": NotifyVonage, |
| 112 |
}, |
| 113 |
), |
| 114 |
( |
| 115 |
"vonage://_?key=AC{}&secret={}&source={}".format( |
| 116 |
"a" * 8, "b" * 16, "5" * 11 |
| 117 |
), |
| 118 |
{ |
| 119 |
|
| 120 |
|
| 121 |
"instance": NotifyVonage, |
| 122 |
}, |
| 123 |
), |
| 124 |
( |
| 125 |
"vonage://_?key=AC{}&secret={}&from={}&to={}".format( |
| 126 |
"a" * 8, "b" * 16, "5" * 11, "7" * 13 |
| 127 |
), |
| 128 |
{ |
| 129 |
|
| 130 |
"instance": NotifyVonage, |
| 131 |
}, |
| 132 |
), |
| 133 |
( |
| 134 |
"vonage://AC{}:{}@{}".format("a" * 8, "b" * 16, "6" * 11), |
| 135 |
{ |
| 136 |
"instance": NotifyVonage, |
| 137 |
|
| 138 |
"response": False, |
| 139 |
"requests_response_code": 999, |
| 140 |
}, |
| 141 |
), |
| 142 |
( |
| 143 |
"vonage://AC{}:{}@{}".format("a" * 8, "b" * 16, "6" * 11), |
| 144 |
{ |
| 145 |
"instance": NotifyVonage, |
| 146 |
|
| 147 |
|
| 148 |
"test_requests_exceptions": True, |
| 149 |
}, |
| 150 |
), |
| 151 |
|
| 152 |
( |
| 153 |
"nexmo://", |
| 154 |
{ |
| 155 |
|
| 156 |
"instance": TypeError, |
| 157 |
}, |
| 158 |
), |
| 159 |
( |
| 160 |
"nexmo://:@/", |
| 161 |
{ |
| 162 |
|
| 163 |
"instance": TypeError, |
| 164 |
}, |
| 165 |
), |
| 166 |
( |
| 167 |
"nexmo://AC{}@12345678".format("a" * 8), |
| 168 |
{ |
| 169 |
|
| 170 |
"instance": TypeError, |
| 171 |
}, |
| 172 |
), |
| 173 |
( |
| 174 |
"nexmo://AC{}:{}@{}".format("a" * 8, "b" * 16, "3" * 9), |
| 175 |
{ |
| 176 |
|
| 177 |
"instance": TypeError, |
| 178 |
}, |
| 179 |
), |
| 180 |
( |
| 181 |
"nexmo://AC{}:{}@{}/?ttl=0".format("b" * 8, "c" * 16, "3" * 11), |
| 182 |
{ |
| 183 |
|
| 184 |
"instance": TypeError, |
| 185 |
}, |
| 186 |
), |
| 187 |
( |
| 188 |
"nexmo://AC{}:{}@{}".format("d" * 8, "e" * 16, "a" * 11), |
| 189 |
{ |
| 190 |
|
| 191 |
"instance": TypeError, |
| 192 |
}, |
| 193 |
), |
| 194 |
( |
| 195 |
"nexmo://AC{}:{}@{}/123/{}/abcd/".format( |
| 196 |
"f" * 8, "g" * 16, "3" * 11, "9" * 15 |
| 197 |
), |
| 198 |
{ |
| 199 |
|
| 200 |
"instance": NotifyVonage, |
| 201 |
|
| 202 |
"privacy_url": "vonage://A...f:****@", |
| 203 |
}, |
| 204 |
), |
| 205 |
( |
| 206 |
"nexmo://AC{}:{}@{}".format("h" * 8, "i" * 16, "5" * 11), |
| 207 |
{ |
| 208 |
|
| 209 |
|
| 210 |
"instance": NotifyVonage, |
| 211 |
}, |
| 212 |
), |
| 213 |
( |
| 214 |
"nexmo://_?key=AC{}&secret={}&from={}".format( |
| 215 |
"a" * 8, "b" * 16, "5" * 11 |
| 216 |
), |
| 217 |
{ |
| 218 |
|
| 219 |
"instance": NotifyVonage, |
| 220 |
}, |
| 221 |
), |
| 222 |
( |
| 223 |
"nexmo://_?key=AC{}&secret={}&source={}".format( |
| 224 |
"a" * 8, "b" * 16, "5" * 11 |
| 225 |
), |
| 226 |
{ |
| 227 |
|
| 228 |
|
| 229 |
"instance": NotifyVonage, |
| 230 |
}, |
| 231 |
), |
| 232 |
( |
| 233 |
"nexmo://_?key=AC{}&secret={}&from={}&to={}".format( |
| 234 |
"a" * 8, "b" * 16, "5" * 11, "7" * 13 |
| 235 |
), |
| 236 |
{ |
| 237 |
|
| 238 |
"instance": NotifyVonage, |
| 239 |
}, |
| 240 |
), |
| 241 |
( |
| 242 |
"nexmo://AC{}:{}@{}".format("a" * 8, "b" * 16, "6" * 11), |
| 243 |
{ |
| 244 |
"instance": NotifyVonage, |
| 245 |
|
| 246 |
"response": False, |
| 247 |
"requests_response_code": 999, |
| 248 |
}, |
| 249 |
), |
| 250 |
( |
| 251 |
"nexmo://AC{}:{}@{}".format("a" * 8, "b" * 16, "6" * 11), |
| 252 |
{ |
| 253 |
"instance": NotifyVonage, |
| 254 |
|
| 255 |
|
| 256 |
"test_requests_exceptions": True, |
| 257 |
}, |
| 258 |
), |
| 259 |
) |
| 260 |
|
| 261 |
|
| 262 |
def test_plugin_vonage_urls(): |
| 263 |
"""NotifyVonage() Apprise URLs.""" |
| 264 |
|
| 265 |
|
| 266 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 267 |
|
| 268 |
|
| 269 |
@mock.patch("requests.post") |
| 270 |
def test_plugin_vonage_edge_cases(mock_post): |
| 271 |
"""NotifyVonage() Edge Cases.""" |
| 272 |
|
| 273 |
|
| 274 |
response = requests.Request() |
| 275 |
response.status_code = requests.codes.ok |
| 276 |
|
| 277 |
|
| 278 |
mock_post.return_value = response |
| 279 |
|
| 280 |
|
| 281 |
apikey = "AC{}".format("b" * 8) |
| 282 |
secret = "{}".format("b" * 16) |
| 283 |
source = "+1 (555) 123-3456" |
| 284 |
|
| 285 |
|
| 286 |
with pytest.raises(TypeError): |
| 287 |
NotifyVonage(apikey=None, secret=secret, source=source) |
| 288 |
|
| 289 |
with pytest.raises(TypeError): |
| 290 |
NotifyVonage(apikey=" ", secret=secret, source=source) |
| 291 |
|
| 292 |
|
| 293 |
with pytest.raises(TypeError): |
| 294 |
NotifyVonage(apikey=apikey, secret=None, source=source) |
| 295 |
|
| 296 |
with pytest.raises(TypeError): |
| 297 |
NotifyVonage(apikey=apikey, secret=" ", source=source) |
| 298 |
|
| 299 |
|
| 300 |
response.status_code = 400 |
| 301 |
response.content = dumps( |
| 302 |
{ |
| 303 |
"code": 21211, |
| 304 |
"message": "The 'To' number +1234567 is not a valid phone number.", |
| 305 |
} |
| 306 |
) |
| 307 |
mock_post.return_value = response |
| 308 |
|
| 309 |
|
| 310 |
obj = NotifyVonage(apikey=apikey, secret=secret, source=source) |
| 311 |
|
| 312 |
|
| 313 |
assert obj.notify("title", "body", "info") is False |