Debian Codegraph @

tests/test_plugin_zulip.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
31 from helpers import AppriseURLTester
32 import pytest
33 import requests
34
35 from apprise.exception import AppriseImproperlyConfigured
36 from apprise.plugins.zulip import NotifyZulip
37
38 logging.disable(logging.CRITICAL)
39
40 # Our Testing URLs
41 apprise_url_tests = (
42 (
43 "zulip://",
44 {
45 "instance": AppriseImproperlyConfigured,
46 },
47 ),
48 (
49 "zulip://:@/",
50 {
51 "instance": AppriseImproperlyConfigured,
52 },
53 ),
54 (
55 "zulip://apprise",
56 {
57 # Just org provided (no token or botname)
58 "instance": AppriseImproperlyConfigured,
59 },
60 ),
61 (
62 "zulip://botname@apprise",
63 {
64 # Just org and botname provided (no token)
65 "instance": AppriseImproperlyConfigured,
66 },
67 ),
68 # invalid token
69 (
70 "zulip://botname@apprise/{}".format("a" * 24),
71 {
72 "instance": AppriseImproperlyConfigured,
73 },
74 ),
75 # invalid botname
76 (
77 "zulip://....@apprise/{}".format("a" * 32),
78 {
79 "instance": AppriseImproperlyConfigured,
80 },
81 ),
82 # Valid everything - botname with a dash
83 (
84 "zulip://bot-name@apprise/{}".format("a" * 32),
85 {
86 "instance": NotifyZulip,
87 "privacy_url": "zulip://bot-name@apprise/a...a/",
88 },
89 ),
90 # Valid everything - no target so default is used
91 (
92 "zulip://botname@apprise/{}".format("a" * 32),
93 {
94 "instance": NotifyZulip,
95 # Our expected url(privacy=True) startswith() response:
96 "privacy_url": "zulip://botname@apprise/a...a/",
97 },
98 ),
99 # Valid everything - organization as hostname
100 (
101 "zulip://[email protected]/{}".format("a" * 32),
102 {
103 "instance": NotifyZulip,
104 },
105 ),
106 # Valid everything - 2 streams specified
107 (
108 "zulip://botname@apprise/{}/channel1/channel2".format("a" * 32),
109 {
110 "instance": NotifyZulip,
111 },
112 ),
113 # Valid everything - 2 streams specified (using to=)
114 (
115 "zulip://botname@apprise/{}/?to=channel1/channel2".format("a" * 32),
116 {
117 "instance": NotifyZulip,
118 },
119 ),
120 # Test token=
121 (
122 "zulip://botname@apprise/?token={}&to=channel1".format("a" * 32),
123 {
124 "instance": NotifyZulip,
125 },
126 ),
127 # Valid everything - 2 emails specified
128 (
129 "zulip://botname@apprise/{}/[email protected]/[email protected]".format(
130 "a" * 32
131 ),
132 {
133 "instance": NotifyZulip,
134 },
135 ),
136 (
137 "zulip://botname@apprise/{}".format("a" * 32),
138 {
139 "instance": NotifyZulip,
140 # don't include an image by default
141 "include_image": False,
142 },
143 ),
144 (
145 "zulip://botname@apprise/{}".format("a" * 32),
146 {
147 "instance": NotifyZulip,
148 # force a failure
149 "response": False,
150 "requests_response_code": requests.codes.internal_server_error,
151 },
152 ),
153 (
154 "zulip://botname@apprise/{}".format("a" * 32),
155 {
156 "instance": NotifyZulip,
157 # throw a bizarre code forcing us to fail to look it up
158 "response": False,
159 "requests_response_code": 999,
160 },
161 ),
162 (
163 "zulip://botname@apprise/{}".format("a" * 32),
164 {
165 "instance": NotifyZulip,
166 # Throws a series of i/o exceptions with this flag
167 # is set and tests that we gracefully handle them
168 "test_requests_exceptions": True,
169 },
170 ),
171 )
172
173
174 def test_plugin_zulip_urls():
175 """NotifyZulip() Apprise URLs."""
176
177 # Run our general tests
178 AppriseURLTester(tests=apprise_url_tests).run_all()
179
180
181 def test_plugin_zulip_edge_cases():
182 """NotifyZulip() Edge Cases."""
183
184 # must be 32 characters long
185 token = "a" * 32
186
187 # Invalid organization
188 with pytest.raises(AppriseImproperlyConfigured):
189 NotifyZulip(botname="test", organization="#", token=token)