| 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 loads |
| 29 |
|
| 30 |
|
| 31 |
import logging |
| 32 |
from unittest import mock |
| 33 |
|
| 34 |
from helpers import AppriseURLTester |
| 35 |
import requests |
| 36 |
|
| 37 |
from apprise import Apprise, NotifyType |
| 38 |
from apprise.plugins.httpsms import NotifyHttpSMS |
| 39 |
|
| 40 |
logging.disable(logging.CRITICAL) |
| 41 |
|
| 42 |
|
| 43 |
apprise_url_tests = ( |
| 44 |
( |
| 45 |
"httpsms://", |
| 46 |
{ |
| 47 |
|
| 48 |
"instance": TypeError, |
| 49 |
}, |
| 50 |
), |
| 51 |
( |
| 52 |
"httpsms://:@/", |
| 53 |
{ |
| 54 |
|
| 55 |
"instance": TypeError, |
| 56 |
}, |
| 57 |
), |
| 58 |
( |
| 59 |
"httpsms://{}:{}@{}".format("u" * 10, "p" * 10, "3" * 5), |
| 60 |
{ |
| 61 |
|
| 62 |
"instance": TypeError, |
| 63 |
}, |
| 64 |
), |
| 65 |
( |
| 66 |
"httpsms://{}@{}/{}".format("p" * 10, "1" * 10, 2 * "5"), |
| 67 |
{ |
| 68 |
|
| 69 |
"instance": NotifyHttpSMS, |
| 70 |
|
| 71 |
"notify_response": False, |
| 72 |
}, |
| 73 |
), |
| 74 |
( |
| 75 |
"httpsms://{}@{}".format("p" * 10, "2" * 10), |
| 76 |
{ |
| 77 |
|
| 78 |
"instance": NotifyHttpSMS, |
| 79 |
}, |
| 80 |
), |
| 81 |
( |
| 82 |
"httpsms://{}@9876543210/{}/abcd/".format("b" * 10, "3" * 11), |
| 83 |
{ |
| 84 |
|
| 85 |
|
| 86 |
"instance": NotifyHttpSMS, |
| 87 |
"privacy_url": "httpsms://b...b@9876543210/33333333333", |
| 88 |
}, |
| 89 |
), |
| 90 |
( |
| 91 |
"httpsms://{}@{}".format("c" * 10, "4" * 11), |
| 92 |
{ |
| 93 |
"instance": NotifyHttpSMS, |
| 94 |
|
| 95 |
"privacy_url": "httpsms://c...c@44444444444", |
| 96 |
}, |
| 97 |
), |
| 98 |
( |
| 99 |
"httpsms://{}@{}".format("b" * 10, "5" * 11), |
| 100 |
{ |
| 101 |
|
| 102 |
"instance": NotifyHttpSMS, |
| 103 |
}, |
| 104 |
), |
| 105 |
( |
| 106 |
"httpsms://?key={}&from={}".format("y" * 10, "5" * 11), |
| 107 |
{ |
| 108 |
|
| 109 |
"instance": NotifyHttpSMS, |
| 110 |
}, |
| 111 |
), |
| 112 |
( |
| 113 |
"httpsms://?key={}&from={}&to={}".format("b" * 10, "5" * 11, "7" * 13), |
| 114 |
{ |
| 115 |
|
| 116 |
"instance": NotifyHttpSMS, |
| 117 |
}, |
| 118 |
), |
| 119 |
( |
| 120 |
"httpsms://{}@{}".format("b" * 10, "5" * 11), |
| 121 |
{ |
| 122 |
"instance": NotifyHttpSMS, |
| 123 |
|
| 124 |
"response": False, |
| 125 |
"requests_response_code": 999, |
| 126 |
}, |
| 127 |
), |
| 128 |
( |
| 129 |
"httpsms://{}@{}".format("b" * 10, "5" * 11), |
| 130 |
{ |
| 131 |
"instance": NotifyHttpSMS, |
| 132 |
|
| 133 |
|
| 134 |
"test_requests_exceptions": True, |
| 135 |
}, |
| 136 |
), |
| 137 |
) |
| 138 |
|
| 139 |
|
| 140 |
def test_plugin_httpsms_urls(): |
| 141 |
"""NotifyTemplate() Apprise URLs.""" |
| 142 |
|
| 143 |
|
| 144 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 145 |
|
| 146 |
|
| 147 |
@mock.patch("requests.post") |
| 148 |
def test_plugin_httpsms_edge_cases(mock_post): |
| 149 |
"""NotifyHttpSMS() Edge Cases.""" |
| 150 |
|
| 151 |
|
| 152 |
apikey = "mykey123" |
| 153 |
source = "1 (405) 123 1234" |
| 154 |
targets = [ |
| 155 |
"+1(555) 123-1234", |
| 156 |
"1555 5555555", |
| 157 |
|
| 158 |
"12", |
| 159 |
|
| 160 |
"@12", |
| 161 |
] |
| 162 |
|
| 163 |
|
| 164 |
response = requests.Request() |
| 165 |
response.status_code = requests.codes.ok |
| 166 |
|
| 167 |
|
| 168 |
mock_post.return_value = response |
| 169 |
|
| 170 |
|
| 171 |
obj = Apprise.instantiate( |
| 172 |
"httpsms://{}@{}/{}".format(apikey, source, "/".join(targets)) |
| 173 |
) |
| 174 |
|
| 175 |
assert ( |
| 176 |
obj.notify(body="body", title="title", notify_type=NotifyType.INFO) |
| 177 |
is True |
| 178 |
) |
| 179 |
|
| 180 |
|
| 181 |
assert len(obj) == 2 |
| 182 |
|
| 183 |
|
| 184 |
assert mock_post.call_count == 2 |
| 185 |
|
| 186 |
|
| 187 |
details = mock_post.call_args_list[0] |
| 188 |
payload = loads(details[1]["data"]) |
| 189 |
assert payload["from"] == "+14051231234" |
| 190 |
assert payload["to"] == "+15551231234" |
| 191 |
assert payload["content"] == "title\r\nbody" |
| 192 |
|
| 193 |
details = mock_post.call_args_list[1] |
| 194 |
payload = loads(details[1]["data"]) |
| 195 |
assert payload["from"] == "+14051231234" |
| 196 |
assert payload["to"] == "+15555555555" |
| 197 |
assert payload["content"] == "title\r\nbody" |
| 198 |
|
| 199 |
|
| 200 |
assert obj.url().startswith( |
| 201 |
"httpsms://mykey123@14051231234/15551231234/15555555555" |
| 202 |
) |