Debian Codegraph @

tests/test_plugin_messagebird.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 pytest
34 import requests
35
36 from apprise.plugins.messagebird import NotifyMessageBird
37
38 logging.disable(logging.CRITICAL)
39
40 # Our Testing URLs
41 apprise_url_tests = (
42 (
43 "msgbird://",
44 {
45 # No hostname/apikey specified
46 "instance": TypeError,
47 },
48 ),
49 (
50 "msgbird://{}/abcd".format("a" * 25),
51 {
52 # invalid characters in source phone number
53 "instance": TypeError,
54 },
55 ),
56 (
57 "msgbird://{}/123".format("a" * 25),
58 {
59 # invalid source phone number
60 "instance": TypeError,
61 },
62 ),
63 (
64 "msgbird://{}/15551232000".format("a" * 25),
65 {
66 # target phone number becomes who we text too; all is good
67 "instance": NotifyMessageBird,
68 # Our expected url(privacy=True) startswith() response:
69 "privacy_url": "msgbird://a...a/15551232000",
70 },
71 ),
72 (
73 "msgbird://{}/15551232000/abcd".format("a" * 25),
74 {
75 # valid credentials
76 "instance": NotifyMessageBird,
77 # Since there are no targets specified we expect a False return on
78 # send()
79 "notify_response": False,
80 },
81 ),
82 (
83 "msgbird://{}/15551232000/123".format("a" * 25),
84 {
85 # valid credentials
86 "instance": NotifyMessageBird,
87 # Since there are no targets specified we expect a False return on
88 # send()
89 "notify_response": False,
90 },
91 ),
92 (
93 "msgbird://{}/?from=15551233000&to=15551232000".format("a" * 25),
94 {
95 # reference to to= and from=
96 "instance": NotifyMessageBird,
97 },
98 ),
99 (
100 "msgbird://{}/15551232000".format("a" * 25),
101 {
102 "instance": NotifyMessageBird,
103 # force a failure
104 "response": False,
105 "requests_response_code": requests.codes.internal_server_error,
106 },
107 ),
108 (
109 "msgbird://{}/15551232000".format("a" * 25),
110 {
111 "instance": NotifyMessageBird,
112 # throw a bizarre code forcing us to fail to look it up
113 "response": False,
114 "requests_response_code": 999,
115 },
116 ),
117 (
118 "msgbird://{}/15551232000".format("a" * 25),
119 {
120 "instance": NotifyMessageBird,
121 # Throws a series of i/o exceptions with this flag
122 # is set and tests that we gracefully handle them
123 "test_requests_exceptions": True,
124 },
125 ),
126 )
127
128
129 def test_plugin_messagebird_urls():
130 """NotifyTemplate() Apprise URLs."""
131
132 # Run our general tests
133 AppriseURLTester(tests=apprise_url_tests).run_all()
134
135
136 @mock.patch("requests.post")
137 def test_plugin_messagebird_edge_cases(mock_post):
138 """NotifyMessageBird() Edge Cases."""
139
140 # Prepare our response
141 response = requests.Request()
142 response.status_code = requests.codes.ok
143
144 # Prepare Mock
145 mock_post.return_value = response
146
147 # Initialize some generic (but valid) tokens
148 # authkey = '{}'.format('a' * 24)
149 source = "+1 (555) 123-3456"
150
151 # No apikey specified
152 with pytest.raises(TypeError):
153 NotifyMessageBird(apikey=None, source=source)
154 with pytest.raises(TypeError):
155 NotifyMessageBird(apikey=" ", source=source)