Debian Codegraph @

tests/test_plugin_pushdeer.py

raw symbols SCIP
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.plugins.pushdeer import NotifyPushDeer
37
38 logging.disable(logging.CRITICAL)
39
40 # Our Testing URLs
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 # throw a bizarre code forcing us to fail to look it up
59 "response": False,
60 "requests_response_code": 999,
61 },
62 ),
63 (
64 "pushdeer://localhost/{}".format("a" * 8),
65 {
66 "instance": NotifyPushDeer,
67 # Throws a series of i/o exceptions with this flag
68 # is set and tests that we gracefully handle them
69 "test_requests_exceptions": True,
70 },
71 ),
72 (
73 "pushdeer://localhost:80/{}".format("a" * 8),
74 {
75 "instance": NotifyPushDeer,
76 # throw a bizarre code forcing us to fail to look it up
77 "response": False,
78 "requests_response_code": 999,
79 },
80 ),
81 (
82 "pushdeer://localhost:80/{}".format("a" * 8),
83 {
84 "instance": NotifyPushDeer,
85 # Throws a series of i/o exceptions with this flag
86 # is set and tests that we gracefully handle them
87 "test_requests_exceptions": True,
88 },
89 ),
90 (
91 "pushdeer://{}".format("a" * 8),
92 {
93 "instance": NotifyPushDeer,
94 # throw a bizarre code forcing us to fail to look it up
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 # Throws a series of i/o exceptions with this flag
104 # is set and tests that we gracefully handle them
105 "test_requests_exceptions": True,
106 },
107 ),
108 )
109
110
111 def test_plugin_pushdeer_urls():
112 """NotifyPushDeer() Apprise URLs."""
113
114 # Run our general tests
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 # Prepare Mock
127 mock_post.return_value = response
128
129 # Variation Initializations
130 obj = Apprise.instantiate("pushdeer://localhost/pushKey")
131 assert isinstance(obj, NotifyPushDeer)
132 assert isinstance(obj.url(), str)
133
134 # Send Notification
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 )