| 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 pytest |
| 34 |
import requests |
| 35 |
|
| 36 |
from apprise.plugins.messagebird import NotifyMessageBird |
| 37 |
|
| 38 |
logging.disable(logging.CRITICAL) |
| 39 |
|
| 40 |
|
| 41 |
apprise_url_tests = ( |
| 42 |
( |
| 43 |
"msgbird://", |
| 44 |
{ |
| 45 |
|
| 46 |
"instance": TypeError, |
| 47 |
}, |
| 48 |
), |
| 49 |
( |
| 50 |
"msgbird://{}/abcd".format("a" * 25), |
| 51 |
{ |
| 52 |
|
| 53 |
"instance": TypeError, |
| 54 |
}, |
| 55 |
), |
| 56 |
( |
| 57 |
"msgbird://{}/123".format("a" * 25), |
| 58 |
{ |
| 59 |
|
| 60 |
"instance": TypeError, |
| 61 |
}, |
| 62 |
), |
| 63 |
( |
| 64 |
"msgbird://{}/15551232000".format("a" * 25), |
| 65 |
{ |
| 66 |
|
| 67 |
"instance": NotifyMessageBird, |
| 68 |
|
| 69 |
"privacy_url": "msgbird://a...a/15551232000", |
| 70 |
}, |
| 71 |
), |
| 72 |
( |
| 73 |
"msgbird://{}/15551232000/abcd".format("a" * 25), |
| 74 |
{ |
| 75 |
|
| 76 |
"instance": NotifyMessageBird, |
| 77 |
|
| 78 |
|
| 79 |
"notify_response": False, |
| 80 |
}, |
| 81 |
), |
| 82 |
( |
| 83 |
"msgbird://{}/15551232000/123".format("a" * 25), |
| 84 |
{ |
| 85 |
|
| 86 |
"instance": NotifyMessageBird, |
| 87 |
|
| 88 |
|
| 89 |
"notify_response": False, |
| 90 |
}, |
| 91 |
), |
| 92 |
( |
| 93 |
"msgbird://{}/?from=15551233000&to=15551232000".format("a" * 25), |
| 94 |
{ |
| 95 |
|
| 96 |
"instance": NotifyMessageBird, |
| 97 |
}, |
| 98 |
), |
| 99 |
( |
| 100 |
"msgbird://{}/15551232000".format("a" * 25), |
| 101 |
{ |
| 102 |
"instance": NotifyMessageBird, |
| 103 |
|
| 104 |
"response": False, |
| 105 |
"requests_response_code": requests.codes.internal_server_error, |
| 106 |
}, |
| 107 |
), |
| 108 |
( |
| 109 |
"msgbird://{}/15551232000".format("a" * 25), |
| 110 |
{ |
| 111 |
"instance": NotifyMessageBird, |
| 112 |
|
| 113 |
"response": False, |
| 114 |
"requests_response_code": 999, |
| 115 |
}, |
| 116 |
), |
| 117 |
( |
| 118 |
"msgbird://{}/15551232000".format("a" * 25), |
| 119 |
{ |
| 120 |
"instance": NotifyMessageBird, |
| 121 |
|
| 122 |
|
| 123 |
"test_requests_exceptions": True, |
| 124 |
}, |
| 125 |
), |
| 126 |
) |
| 127 |
|
| 128 |
|
| 129 |
def test_plugin_messagebird_urls(): |
| 130 |
"""NotifyTemplate() Apprise URLs.""" |
| 131 |
|
| 132 |
|
| 133 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 134 |
|
| 135 |
|
| 136 |
@mock.patch("requests.post") |
| 137 |
def test_plugin_messagebird_edge_cases(mock_post): |
| 138 |
"""NotifyMessageBird() Edge Cases.""" |
| 139 |
|
| 140 |
|
| 141 |
response = requests.Request() |
| 142 |
response.status_code = requests.codes.ok |
| 143 |
|
| 144 |
|
| 145 |
mock_post.return_value = response |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
source = "+1 (555) 123-3456" |
| 150 |
|
| 151 |
|
| 152 |
with pytest.raises(TypeError): |
| 153 |
NotifyMessageBird(apikey=None, source=source) |
| 154 |
with pytest.raises(TypeError): |
| 155 |
NotifyMessageBird(apikey=" ", source=source) |