Debian Codegraph @

tests/test_plugin_guilded.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 import os
31 from unittest import mock
32
33 from helpers import AppriseURLTester
34 import pytest
35 import requests
36
37 from apprise.plugins.guilded import NotifyGuilded
38
39 logging.disable(logging.CRITICAL)
40
41 # Attachment Directory
42 TEST_VAR_DIR = os.path.join(os.path.dirname(__file__), "var")
43
44 # Our Testing URLs
45 apprise_url_tests = (
46 (
47 "guilded://",
48 {
49 "instance": TypeError,
50 },
51 ),
52 # An invalid url
53 (
54 "guilded://:@/",
55 {
56 "instance": TypeError,
57 },
58 ),
59 # No webhook_token specified
60 (
61 "guilded://%s" % ("i" * 24),
62 {
63 "instance": TypeError,
64 },
65 ),
66 # Provide both an webhook id and a webhook token
67 (
68 "guilded://{}/{}".format("i" * 24, "t" * 64),
69 {
70 "instance": NotifyGuilded,
71 "requests_response_code": requests.codes.no_content,
72 },
73 ),
74 # Provide a temporary username
75 (
76 "guilded://l2g@{}/{}".format("i" * 24, "t" * 64),
77 {
78 "instance": NotifyGuilded,
79 "requests_response_code": requests.codes.no_content,
80 },
81 ),
82 # test image= field
83 (
84 "guilded://{}/{}?format=markdown&footer=Yes&image=Yes".format(
85 "i" * 24, "t" * 64
86 ),
87 {
88 "instance": NotifyGuilded,
89 "requests_response_code": requests.codes.no_content,
90 # don't include an image by default
91 "include_image": False,
92 },
93 ),
94 (
95 "guilded://{}/{}?format=markdown&footer=Yes&image=No&fields=no".format(
96 "i" * 24, "t" * 64
97 ),
98 {
99 "instance": NotifyGuilded,
100 "requests_response_code": requests.codes.no_content,
101 },
102 ),
103 (
104 "guilded://{}/{}?format=markdown&footer=Yes&image=Yes".format(
105 "i" * 24, "t" * 64
106 ),
107 {
108 "instance": NotifyGuilded,
109 "requests_response_code": requests.codes.no_content,
110 },
111 ),
112 (
113 "https://media.guilded.gg/webhooks/{}/{}".format("0" * 10, "B" * 40),
114 {
115 # Native URL Support, support the provided guilded URL from their
116 # webpage.
117 "instance": NotifyGuilded,
118 "requests_response_code": requests.codes.no_content,
119 },
120 ),
121 (
122 "guilded://{}/{}?format=markdown&avatar=No&footer=No".format(
123 "i" * 24, "t" * 64
124 ),
125 {
126 "instance": NotifyGuilded,
127 "requests_response_code": requests.codes.no_content,
128 },
129 ),
130 # different format support
131 (
132 "guilded://{}/{}?format=markdown".format("i" * 24, "t" * 64),
133 {
134 "instance": NotifyGuilded,
135 "requests_response_code": requests.codes.no_content,
136 },
137 ),
138 (
139 "guilded://{}/{}?format=text".format("i" * 24, "t" * 64),
140 {
141 "instance": NotifyGuilded,
142 "requests_response_code": requests.codes.no_content,
143 },
144 ),
145 # Test with avatar URL
146 (
147 "guilded://{}/{}?avatar_url=http://localhost/test.jpg".format(
148 "i" * 24, "t" * 64
149 ),
150 {
151 "instance": NotifyGuilded,
152 "requests_response_code": requests.codes.no_content,
153 },
154 ),
155 # Test without image set
156 (
157 "guilded://{}/{}".format("i" * 24, "t" * 64),
158 {
159 "instance": NotifyGuilded,
160 "requests_response_code": requests.codes.no_content,
161 # don't include an image by default
162 "include_image": False,
163 },
164 ),
165 (
166 "guilded://{}/{}/".format("a" * 24, "b" * 64),
167 {
168 "instance": NotifyGuilded,
169 # force a failure
170 "response": False,
171 "requests_response_code": requests.codes.internal_server_error,
172 },
173 ),
174 (
175 "guilded://{}/{}/".format("a" * 24, "b" * 64),
176 {
177 "instance": NotifyGuilded,
178 # throw a bizarre code forcing us to fail to look it up
179 "response": False,
180 "requests_response_code": 999,
181 },
182 ),
183 (
184 "guilded://{}/{}/".format("a" * 24, "b" * 64),
185 {
186 "instance": NotifyGuilded,
187 # Throws a series of i/o exceptions with this flag
188 # is set and tests that we gracefully handle them
189 "test_requests_exceptions": True,
190 },
191 ),
192 )
193
194
195 def test_plugin_guilded_urls():
196 """NotifyGuilded() Apprise URLs."""
197
198 # Run our general tests
199 AppriseURLTester(tests=apprise_url_tests).run_all()
200
201
202 @mock.patch("requests.post")
203 def test_plugin_guilded_general(mock_post):
204 """NotifyGuilded() General Checks."""
205
206 # Initialize some generic (but valid) tokens
207 webhook_id = "A" * 24
208 webhook_token = "B" * 64
209
210 # Prepare Mock
211 mock_post.return_value = requests.Request()
212 mock_post.return_value.status_code = requests.codes.ok
213
214 # Invalid webhook id
215 with pytest.raises(TypeError):
216 NotifyGuilded(webhook_id=None, webhook_token=webhook_token)
217 # Invalid webhook id (whitespace)
218 with pytest.raises(TypeError):
219 NotifyGuilded(webhook_id=" ", webhook_token=webhook_token)
220
221 # Invalid webhook token
222 with pytest.raises(TypeError):
223 NotifyGuilded(webhook_id=webhook_id, webhook_token=None)
224 # Invalid webhook token (whitespace)
225 with pytest.raises(TypeError):
226 NotifyGuilded(webhook_id=webhook_id, webhook_token=" ")
227
228 obj = NotifyGuilded(
229 webhook_id=webhook_id,
230 webhook_token=webhook_token,
231 footer=True,
232 thumbnail=False,
233 )
234
235 # Test that we get a string response
236 assert isinstance(obj.url(), str)