| 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 |
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 |
|
| 41 |
apprise_url_tests = ( |
| 42 |
( |
| 43 |
"clickatell://", |
| 44 |
{ |
| 45 |
|
| 46 |
"instance": TypeError, |
| 47 |
}, |
| 48 |
), |
| 49 |
( |
| 50 |
"clickatell:///", |
| 51 |
{ |
| 52 |
|
| 53 |
"instance": TypeError, |
| 54 |
}, |
| 55 |
), |
| 56 |
( |
| 57 |
"clickatell://@/", |
| 58 |
{ |
| 59 |
|
| 60 |
"instance": TypeError, |
| 61 |
}, |
| 62 |
), |
| 63 |
( |
| 64 |
"clickatell://{}@/".format("1" * 10), |
| 65 |
{ |
| 66 |
|
| 67 |
"instance": TypeError, |
| 68 |
}, |
| 69 |
), |
| 70 |
( |
| 71 |
"clickatell://{}@{}/".format("1" * 3, "a" * 32), |
| 72 |
{ |
| 73 |
|
| 74 |
"instance": TypeError |
| 75 |
}, |
| 76 |
), |
| 77 |
( |
| 78 |
"clickatell://{}/".format("a" * 32), |
| 79 |
{ |
| 80 |
|
| 81 |
"instance": NotifyClickatell, |
| 82 |
|
| 83 |
"notify_response": False, |
| 84 |
}, |
| 85 |
), |
| 86 |
( |
| 87 |
"clickatell://{}@{}/".format("1" * 10, "a" * 32), |
| 88 |
{ |
| 89 |
|
| 90 |
"instance": NotifyClickatell, |
| 91 |
|
| 92 |
"notify_response": False, |
| 93 |
}, |
| 94 |
), |
| 95 |
( |
| 96 |
"clickatell://{}@{}/123/{}/abcd".format("1" * 10, "a" * 32, "3" * 15), |
| 97 |
{ |
| 98 |
|
| 99 |
"instance": NotifyClickatell, |
| 100 |
|
| 101 |
"notify_response": False, |
| 102 |
}, |
| 103 |
), |
| 104 |
( |
| 105 |
"clickatell://{}/{}".format("1" * 10, "a" * 32), |
| 106 |
{ |
| 107 |
|
| 108 |
"instance": NotifyClickatell, |
| 109 |
|
| 110 |
"notify_response": False, |
| 111 |
}, |
| 112 |
), |
| 113 |
( |
| 114 |
"clickatell://{}@{}/{}".format("1" * 10, "a" * 32, "1" * 10), |
| 115 |
{ |
| 116 |
|
| 117 |
"instance": NotifyClickatell, |
| 118 |
}, |
| 119 |
), |
| 120 |
( |
| 121 |
"clickatell://{}/{}".format("a" * 32, "1" * 10), |
| 122 |
{ |
| 123 |
|
| 124 |
"instance": NotifyClickatell, |
| 125 |
}, |
| 126 |
), |
| 127 |
( |
| 128 |
"clickatell://_?apikey={}&from={}&to={},{}".format( |
| 129 |
"a" * 32, "1" * 10, "1" * 10, "1" * 10 |
| 130 |
), |
| 131 |
{ |
| 132 |
|
| 133 |
"instance": NotifyClickatell, |
| 134 |
}, |
| 135 |
), |
| 136 |
( |
| 137 |
"clickatell://_?apikey={}".format("a" * 32), |
| 138 |
{ |
| 139 |
|
| 140 |
"instance": NotifyClickatell, |
| 141 |
"notify_response": False, |
| 142 |
}, |
| 143 |
), |
| 144 |
( |
| 145 |
"clickatell://_?apikey={}&from={}".format("a" * 32, "1" * 10), |
| 146 |
{ |
| 147 |
|
| 148 |
"instance": NotifyClickatell, |
| 149 |
"notify_response": False, |
| 150 |
}, |
| 151 |
), |
| 152 |
( |
| 153 |
"clickatell://{}@{}/{}".format("1" * 10, "a" * 32, "1" * 10), |
| 154 |
{ |
| 155 |
"instance": NotifyClickatell, |
| 156 |
|
| 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 |
|
| 166 |
|
| 167 |
"test_requests_exceptions": True, |
| 168 |
}, |
| 169 |
), |
| 170 |
) |
| 171 |
|
| 172 |
|
| 173 |
def test_plugin_clickatell_urls(): |
| 174 |
"""NotifyClickatell() Apprise URLs.""" |
| 175 |
|
| 176 |
|
| 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 |
|
| 185 |
response = requests.Request() |
| 186 |
response.status_code = requests.codes.ok |
| 187 |
|
| 188 |
|
| 189 |
mock_post.return_value = response |
| 190 |
|
| 191 |
|
| 192 |
apikey = "b" * 32 |
| 193 |
from_phone = "+1 (555) 123-3456" |
| 194 |
|
| 195 |
|
| 196 |
with pytest.raises(TypeError): |
| 197 |
NotifyClickatell(apikey=None, from_phone=from_phone) |
| 198 |
|
| 199 |
|
| 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 |
|
| 210 |
obj = NotifyClickatell(apikey=apikey, from_phone=from_phone) |
| 211 |
|
| 212 |
|
| 213 |
assert obj.notify("title", "body", "info") is False |