| 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 |
|
| 29 |
import logging |
| 30 |
from unittest import mock |
| 31 |
|
| 32 |
from helpers import AppriseURLTester |
| 33 |
import requests |
| 34 |
|
| 35 |
from apprise import Apprise, NotifyType |
| 36 |
from apprise.plugins.fortysixelks import Notify46Elks |
| 37 |
|
| 38 |
logging.disable(logging.CRITICAL) |
| 39 |
|
| 40 |
|
| 41 |
apprise_url_tests = ( |
| 42 |
("46elks://", False), |
| 43 |
("46elks://user@/", False), |
| 44 |
("46elks://:pass@/", False), |
| 45 |
( |
| 46 |
"46elks://user:pass@/", |
| 47 |
{ |
| 48 |
"instance": Notify46Elks, |
| 49 |
|
| 50 |
"notify_response": False, |
| 51 |
}, |
| 52 |
), |
| 53 |
( |
| 54 |
"46elks://user:pass@+15551234556", |
| 55 |
{ |
| 56 |
"instance": Notify46Elks, |
| 57 |
}, |
| 58 |
), |
| 59 |
( |
| 60 |
"46elks://user:pass@+15551234567/+46701234534?from=Acme", |
| 61 |
{ |
| 62 |
"instance": Notify46Elks, |
| 63 |
}, |
| 64 |
), |
| 65 |
|
| 66 |
( |
| 67 |
"elks://user:pass@+15551234123/", |
| 68 |
{ |
| 69 |
"instance": Notify46Elks, |
| 70 |
}, |
| 71 |
), |
| 72 |
|
| 73 |
( |
| 74 |
"46elks://user:pass@+15551234512", |
| 75 |
{ |
| 76 |
"privacy_url": "46elks://user:****@+15551234512", |
| 77 |
"instance": Notify46Elks, |
| 78 |
}, |
| 79 |
), |
| 80 |
|
| 81 |
( |
| 82 |
"46elks://user:pass@Acme/234512", |
| 83 |
{ |
| 84 |
"instance": Notify46Elks, |
| 85 |
"notify_response": False, |
| 86 |
}, |
| 87 |
), |
| 88 |
|
| 89 |
( |
| 90 |
("https://user1:[email protected]/a1/sms?to=+15551234511&from=Acme"), |
| 91 |
{ |
| 92 |
"instance": Notify46Elks, |
| 93 |
"privacy_url": "46elks://user1:****@Acme/+15551234511", |
| 94 |
}, |
| 95 |
), |
| 96 |
( |
| 97 |
"46elks://user:pass@+15551234567", |
| 98 |
{ |
| 99 |
"instance": Notify46Elks, |
| 100 |
|
| 101 |
"response": False, |
| 102 |
"requests_response_code": 999, |
| 103 |
}, |
| 104 |
), |
| 105 |
( |
| 106 |
"46elks://user:pass@+15551234578", |
| 107 |
{ |
| 108 |
"instance": Notify46Elks, |
| 109 |
|
| 110 |
|
| 111 |
"test_requests_exceptions": True, |
| 112 |
}, |
| 113 |
), |
| 114 |
) |
| 115 |
|
| 116 |
|
| 117 |
def test_plugin_46elks_urls(): |
| 118 |
"""NotifyTemplate() Apprise URLs.""" |
| 119 |
|
| 120 |
|
| 121 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 122 |
|
| 123 |
|
| 124 |
@mock.patch("requests.post") |
| 125 |
def test_plugin_46elks_edge_cases(mock_post): |
| 126 |
"""Notify46Elks() Edge Cases.""" |
| 127 |
|
| 128 |
user = "user1" |
| 129 |
password = "pass123" |
| 130 |
phone = "+15551234591" |
| 131 |
|
| 132 |
response = requests.Request() |
| 133 |
response.status_code = requests.codes.ok |
| 134 |
|
| 135 |
|
| 136 |
mock_post.return_value = response |
| 137 |
|
| 138 |
obj = Apprise.instantiate(f"46elks://{user}:{password}@{phone}") |
| 139 |
assert ( |
| 140 |
obj.notify(body="body", title="title", notify_type=NotifyType.INFO) |
| 141 |
is True |
| 142 |
) |
| 143 |
|
| 144 |
|
| 145 |
assert len(obj) == 1 |
| 146 |
|
| 147 |
|
| 148 |
assert mock_post.call_count == 1 |
| 149 |
|
| 150 |
|
| 151 |
details = mock_post.call_args_list[0] |
| 152 |
headers = details[1]["headers"] |
| 153 |
assert headers["User-Agent"] == "Apprise" |
| 154 |
payload = details[1]["data"] |
| 155 |
assert payload["to"] == phone |
| 156 |
assert payload["from"] == phone |
| 157 |
assert payload["message"] == "title\r\nbody" |
| 158 |
|
| 159 |
|
| 160 |
assert obj.url().startswith(f"46elks://{user}:{password}@{phone}") |