Debian Codegraph @

tests/test_plugin_pushdeer.py

raw
1 # BSD 2-Clause License
2 #
3 # Apprise - Push Notification Library.
4 # Copyright (c) 2026, Chris Caron <[email protected]>
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright notice,
13 # this list of conditions and the following disclaimer in the documentation
14 # and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 # POSSIBILITY OF SUCH DAMAGE.
27
28 # Disable logging for a cleaner testing output
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.exception import AppriseImproperlyConfigured
37 from apprise.plugins.pushdeer import NotifyPushDeer
38
39 logging.disable(logging.CRITICAL)
40
41 # Our Testing URLs
42 apprise_url_tests = (
43 (
44 "pushdeer://",
45 {
46 "instance": AppriseImproperlyConfigured,
47 },
48 ),
49 (
50 "pushdeers://",
51 {
52 "instance": AppriseImproperlyConfigured,
53 },
54 ),
55 (
56 "pushdeer://localhost/{}".format("a" * 8),
57 {
58 "instance": NotifyPushDeer,
59 # throw a bizarre code forcing us to fail to look it up
60 "response": False,
61 "requests_response_code": 999,
62 },
63 ),
64 (
65 "pushdeer://localhost/{}".format("a" * 8),
66 {
67 "instance": NotifyPushDeer,
68 # Throws a series of i/o exceptions with this flag
69 # is set and tests that we gracefully handle them
70 "test_requests_exceptions": True,
71 },
72 ),
73 (
74 "pushdeer://localhost:80/{}".format("a" * 8),
75 {
76 "instance": NotifyPushDeer,
77 # throw a bizarre code forcing us to fail to look it up
78 "response": False,
79 "requests_response_code": 999,
80 },
81 ),
82 (
83 "pushdeer://localhost:80/{}".format("a" * 8),
84 {
85 "instance": NotifyPushDeer,
86 # Throws a series of i/o exceptions with this flag
87 # is set and tests that we gracefully handle them
88 "test_requests_exceptions": True,
89 },
90 ),
91 (
92 "pushdeer://{}".format("a" * 8),
93 {
94 "instance": NotifyPushDeer,
95 # throw a bizarre code forcing us to fail to look it up
96 "response": False,
97 "requests_response_code": requests.codes.internal_server_error,
98 },
99 ),
100 (
101 "pushdeer://{}".format("a" * 8),
102 {
103 "instance": NotifyPushDeer,
104 # Throws a series of i/o exceptions with this flag
105 # is set and tests that we gracefully handle them
106 "test_requests_exceptions": True,
107 },
108 ),
109 )
110
111
112 def test_plugin_pushdeer_urls():
113 """NotifyPushDeer() Apprise URLs."""
114
115 # Run our general tests
116 AppriseURLTester(tests=apprise_url_tests).run_all()
117
118
119 @mock.patch("requests.post")
120 def test_plugin_pushdeer_general(mock_post):
121 """NotifyPushDeer() General Checks."""
122
123 response = mock.Mock()
124 response.content = ""
125 response.status_code = requests.codes.ok
126
127 # Prepare Mock
128 mock_post.return_value = response
129
130 # Variation Initializations
131 obj = Apprise.instantiate("pushdeer://localhost/pushKey")
132 assert isinstance(obj, NotifyPushDeer)
133 assert isinstance(obj.url(), str)
134
135 # Send Notification
136 assert obj.send(body="test") is True
137
138 assert mock_post.call_count == 1
139 assert (
140 mock_post.call_args_list[0][0][0]
141 == "http://localhost:80/message/push?pushkey=pushKey"
142 )