Debian Codegraph @

tests/test_plugin_plivo.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
33 from apprise.plugins.plivo import NotifyPlivo
34
35 logging.disable(logging.CRITICAL)
36
37 # Our Testing URLs
38 apprise_url_tests = (
39 (
40 "plivo://",
41 {
42 # No hostname/apikey specified
43 "instance": TypeError,
44 },
45 ),
46 (
47 "plivo://{}@{}/15551232000".format("a" * 10, "a" * 25),
48 {
49 # invalid auth id
50 "instance": TypeError,
51 },
52 ),
53 (
54 "plivo://{}@{}/15551232000".format("a" * 25, "a" * 10),
55 {
56 # invalid token
57 "instance": TypeError,
58 },
59 ),
60 (
61 "plivo://{}@{}/123".format("a" * 25, "a" * 40),
62 {
63 # invalid phone number
64 "instance": TypeError,
65 },
66 ),
67 (
68 "plivo://{}@{}/abc".format("a" * 25, "a" * 40),
69 {
70 # invalid phone number
71 "instance": TypeError,
72 },
73 ),
74 (
75 "plivo://{}@{}/15551231234".format("a" * 25, "b" * 40),
76 {
77 # target phone number becomes who we text too; all is good
78 "instance": NotifyPlivo,
79 },
80 ),
81 (
82 "plivo://{}@{}/15551232000/abcd".format("a" * 25, "a" * 40),
83 {
84 # invalid target phone number
85 "instance": NotifyPlivo,
86 # Notify will fail because it couldn't send to anyone
87 "response": False,
88 },
89 ),
90 (
91 "plivo://{}@{}/15551232000/123".format("a" * 25, "a" * 40),
92 {
93 # invalid target phone number
94 "instance": NotifyPlivo,
95 # Notify will fail because it couldn't send to anyone
96 "response": False,
97 },
98 ),
99 (
100 "plivo://{}@{}/?from=15551233000&to=15551232000&batch=yes".format(
101 "a" * 25, "a" * 40
102 ),
103 {
104 # reference to to= and from=
105 "instance": NotifyPlivo,
106 },
107 ),
108 (
109 "plivo://?id={}&token={}&from=15551233000&to=15551232000".format(
110 "a" * 25, "a" * 40
111 ),
112 {
113 # Our expected url(privacy=True) startswith() response:
114 "privacy_url": "plivo://[email protected]/+15551233000/+15551232000",
115 # reference to to= and from=
116 "instance": NotifyPlivo,
117 },
118 ),
119 (
120 "plivo://15551232123?id={}&token={}&from=15551233000"
121 "&to=15551232000".format("a" * 25, "a" * 40),
122 {
123 # reference to to= and from=
124 "instance": NotifyPlivo,
125 # Our expected url(privacy=True) startswith() response:
126 "privacy_url": "plivo://[email protected]/+15551233000/+15551232123",
127 },
128 ),
129 (
130 "plivo://{}@{}/15551232000".format("a" * 25, "a" * 40),
131 {
132 "instance": NotifyPlivo,
133 # throw a bizarre code forcing us to fail to look it up
134 "response": False,
135 "requests_response_code": 999,
136 },
137 ),
138 (
139 "plivo://{}@{}/15551232000".format("a" * 25, "a" * 40),
140 {
141 "instance": NotifyPlivo,
142 # Throws a series of i/o exceptions with this flag
143 # is set and tests that we gracefully handle them
144 "test_requests_exceptions": True,
145 },
146 ),
147 )
148
149
150 def test_plugin_plivo_urls():
151 """NotifyPlivo() Apprise URLs."""
152
153 # Run our general tests
154 AppriseURLTester(tests=apprise_url_tests).run_all()