| 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.pagerduty import NotifyPagerDuty |
| 37 |
|
| 38 |
logging.disable(logging.CRITICAL) |
| 39 |
|
| 40 |
|
| 41 |
apprise_url_tests = ( |
| 42 |
( |
| 43 |
"pagerduty://", |
| 44 |
{ |
| 45 |
|
| 46 |
"instance": TypeError, |
| 47 |
}, |
| 48 |
), |
| 49 |
( |
| 50 |
"pagerduty://%20@%20/", |
| 51 |
{ |
| 52 |
|
| 53 |
"instance": TypeError, |
| 54 |
}, |
| 55 |
), |
| 56 |
( |
| 57 |
"pagerduty://%20/", |
| 58 |
{ |
| 59 |
|
| 60 |
"instance": TypeError, |
| 61 |
}, |
| 62 |
), |
| 63 |
( |
| 64 |
"pagerduty://%20@abcd/", |
| 65 |
{ |
| 66 |
|
| 67 |
"instance": TypeError, |
| 68 |
}, |
| 69 |
), |
| 70 |
( |
| 71 |
"pagerduty://myroutekey@myapikey/%20", |
| 72 |
{ |
| 73 |
|
| 74 |
"instance": TypeError, |
| 75 |
}, |
| 76 |
), |
| 77 |
( |
| 78 |
"pagerduty://myroutekey@myapikey/mysource/%20", |
| 79 |
{ |
| 80 |
|
| 81 |
"instance": TypeError, |
| 82 |
}, |
| 83 |
), |
| 84 |
( |
| 85 |
"pagerduty://myroutekey@myapikey?region=invalid", |
| 86 |
{ |
| 87 |
|
| 88 |
"instance": TypeError, |
| 89 |
}, |
| 90 |
), |
| 91 |
( |
| 92 |
"pagerduty://myroutekey@myapikey?severity=invalid", |
| 93 |
{ |
| 94 |
|
| 95 |
"instance": TypeError, |
| 96 |
}, |
| 97 |
), |
| 98 |
( |
| 99 |
"pagerduty://myroutekey@myapikey", |
| 100 |
{ |
| 101 |
|
| 102 |
"instance": NotifyPagerDuty, |
| 103 |
|
| 104 |
"privacy_url": "pagerduty://****@****/A...e/N...n?", |
| 105 |
}, |
| 106 |
), |
| 107 |
( |
| 108 |
"pagerduty://myroutekey@myapikey?image=no", |
| 109 |
{ |
| 110 |
|
| 111 |
"instance": NotifyPagerDuty, |
| 112 |
}, |
| 113 |
), |
| 114 |
( |
| 115 |
"pagerduty://myroutekey@myapikey?region=eu", |
| 116 |
{ |
| 117 |
|
| 118 |
"instance": NotifyPagerDuty, |
| 119 |
}, |
| 120 |
), |
| 121 |
( |
| 122 |
"pagerduty://myroutekey@myapikey?severity=critical", |
| 123 |
{ |
| 124 |
|
| 125 |
"instance": NotifyPagerDuty, |
| 126 |
}, |
| 127 |
), |
| 128 |
( |
| 129 |
"pagerduty://myroutekey@myapikey?severity=err", |
| 130 |
{ |
| 131 |
|
| 132 |
"instance": NotifyPagerDuty, |
| 133 |
}, |
| 134 |
), |
| 135 |
|
| 136 |
( |
| 137 |
"pagerduty://myroutekey@myapikey?+key=value&+key2=value2", |
| 138 |
{ |
| 139 |
|
| 140 |
"instance": NotifyPagerDuty, |
| 141 |
}, |
| 142 |
), |
| 143 |
( |
| 144 |
"pagerduty://myroutekey@myapikey/mysource/mycomponent", |
| 145 |
{ |
| 146 |
|
| 147 |
"instance": NotifyPagerDuty, |
| 148 |
|
| 149 |
"privacy_url": "pagerduty://****@****/m...e/m...t?", |
| 150 |
}, |
| 151 |
), |
| 152 |
( |
| 153 |
"pagerduty://routekey@apikey/ms/mc?group=mygroup&class=myclass", |
| 154 |
{ |
| 155 |
|
| 156 |
"instance": NotifyPagerDuty, |
| 157 |
}, |
| 158 |
), |
| 159 |
( |
| 160 |
( |
| 161 |
"pagerduty://?integrationkey=r&apikey=a&source=s&component=c" |
| 162 |
"&group=g&class=c&image=no&click=http://localhost" |
| 163 |
), |
| 164 |
{ |
| 165 |
|
| 166 |
"instance": NotifyPagerDuty |
| 167 |
}, |
| 168 |
), |
| 169 |
( |
| 170 |
"pagerduty://somerkey@someapikey/bizarre/code", |
| 171 |
{ |
| 172 |
"instance": NotifyPagerDuty, |
| 173 |
|
| 174 |
"response": False, |
| 175 |
"requests_response_code": 999, |
| 176 |
}, |
| 177 |
), |
| 178 |
( |
| 179 |
"pagerduty://myroutekey@myapikey/mysource/mycomponent", |
| 180 |
{ |
| 181 |
"instance": NotifyPagerDuty, |
| 182 |
|
| 183 |
|
| 184 |
"test_requests_exceptions": True, |
| 185 |
}, |
| 186 |
), |
| 187 |
) |
| 188 |
|
| 189 |
|
| 190 |
def test_plugin_pagerduty_urls(): |
| 191 |
"""NotifyPagerDuty() Apprise URLs.""" |
| 192 |
|
| 193 |
|
| 194 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 195 |
|
| 196 |
|
| 197 |
@mock.patch("requests.post") |
| 198 |
def test_plugin_pagerduty_notify_type_is_string(mock_post): |
| 199 |
response = mock.Mock() |
| 200 |
response.status_code = requests.codes.ok |
| 201 |
response.content = "" |
| 202 |
mock_post.return_value = response |
| 203 |
|
| 204 |
obj = Apprise.instantiate("pagerduty://myroutekey@myapikey") |
| 205 |
assert isinstance(obj, NotifyPagerDuty) |
| 206 |
|
| 207 |
assert ( |
| 208 |
obj.notify(body="body", title="title", notify_type=NotifyType.INFO) |
| 209 |
is True |
| 210 |
) |
| 211 |
assert mock_post.call_count == 1 |
| 212 |
|
| 213 |
call = mock_post.call_args_list[0] |
| 214 |
|
| 215 |
payload = call[1].get("data") or call[1].get("json") |
| 216 |
payload_text = payload if isinstance(payload, str) else str(payload) |
| 217 |
|
| 218 |
assert "NotifyType." not in payload_text |