| 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 |
| 36 |
from apprise.plugins.pushdeer import NotifyPushDeer |
| 37 |
|
| 38 |
logging.disable(logging.CRITICAL) |
| 39 |
|
| 40 |
|
| 41 |
apprise_url_tests = ( |
| 42 |
( |
| 43 |
"pushdeer://", |
| 44 |
{ |
| 45 |
"instance": TypeError, |
| 46 |
}, |
| 47 |
), |
| 48 |
( |
| 49 |
"pushdeers://", |
| 50 |
{ |
| 51 |
"instance": TypeError, |
| 52 |
}, |
| 53 |
), |
| 54 |
( |
| 55 |
"pushdeer://localhost/{}".format("a" * 8), |
| 56 |
{ |
| 57 |
"instance": NotifyPushDeer, |
| 58 |
|
| 59 |
"response": False, |
| 60 |
"requests_response_code": 999, |
| 61 |
}, |
| 62 |
), |
| 63 |
( |
| 64 |
"pushdeer://localhost/{}".format("a" * 8), |
| 65 |
{ |
| 66 |
"instance": NotifyPushDeer, |
| 67 |
|
| 68 |
|
| 69 |
"test_requests_exceptions": True, |
| 70 |
}, |
| 71 |
), |
| 72 |
( |
| 73 |
"pushdeer://localhost:80/{}".format("a" * 8), |
| 74 |
{ |
| 75 |
"instance": NotifyPushDeer, |
| 76 |
|
| 77 |
"response": False, |
| 78 |
"requests_response_code": 999, |
| 79 |
}, |
| 80 |
), |
| 81 |
( |
| 82 |
"pushdeer://localhost:80/{}".format("a" * 8), |
| 83 |
{ |
| 84 |
"instance": NotifyPushDeer, |
| 85 |
|
| 86 |
|
| 87 |
"test_requests_exceptions": True, |
| 88 |
}, |
| 89 |
), |
| 90 |
( |
| 91 |
"pushdeer://{}".format("a" * 8), |
| 92 |
{ |
| 93 |
"instance": NotifyPushDeer, |
| 94 |
|
| 95 |
"response": False, |
| 96 |
"requests_response_code": requests.codes.internal_server_error, |
| 97 |
}, |
| 98 |
), |
| 99 |
( |
| 100 |
"pushdeer://{}".format("a" * 8), |
| 101 |
{ |
| 102 |
"instance": NotifyPushDeer, |
| 103 |
|
| 104 |
|
| 105 |
"test_requests_exceptions": True, |
| 106 |
}, |
| 107 |
), |
| 108 |
) |
| 109 |
|
| 110 |
|
| 111 |
def test_plugin_pushdeer_urls(): |
| 112 |
"""NotifyPushDeer() Apprise URLs.""" |
| 113 |
|
| 114 |
|
| 115 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 116 |
|
| 117 |
|
| 118 |
@mock.patch("requests.post") |
| 119 |
def test_plugin_pushdeer_general(mock_post): |
| 120 |
"""NotifyPushDeer() General Checks.""" |
| 121 |
|
| 122 |
response = mock.Mock() |
| 123 |
response.content = "" |
| 124 |
response.status_code = requests.codes.ok |
| 125 |
|
| 126 |
|
| 127 |
mock_post.return_value = response |
| 128 |
|
| 129 |
|
| 130 |
obj = Apprise.instantiate("pushdeer://localhost/pushKey") |
| 131 |
assert isinstance(obj, NotifyPushDeer) |
| 132 |
assert isinstance(obj.url(), str) |
| 133 |
|
| 134 |
|
| 135 |
assert obj.send(body="test") is True |
| 136 |
|
| 137 |
assert mock_post.call_count == 1 |
| 138 |
assert ( |
| 139 |
mock_post.call_args_list[0][0][0] |
| 140 |
== "http://localhost:80/message/push?pushkey=pushKey" |
| 141 |
) |