Debian Codegraph @

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