Debian Codegraph @

tests/test_plugin_seven.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 # Disable logging for a cleaner testing output
28 import logging
29 from unittest import mock
30
31 from helpers import AppriseURLTester
32 import pytest
33 import requests
34
35 from apprise.exception import AppriseImproperlyConfigured
36 from apprise.plugins.seven import NotifySeven
37
38 logging.disable(logging.CRITICAL)
39 # Our Testing URLs
40 apprise_url_tests = (
41 (
42 "seven://",
43 {
44 # No hostname/apikey specified
45 "instance": AppriseImproperlyConfigured,
46 },
47 ),
48 (
49 "seven://{}/15551232000".format("a" * 25),
50 {
51 # target phone number becomes who we text too; all is good
52 "instance": NotifySeven,
53 # Our expected url(privacy=True) startswith() response:
54 "privacy_url": "seven://a...a/15551232000",
55 },
56 ),
57 (
58 "seven://{}/15551232000".format("a" * 25),
59 {
60 "instance": NotifySeven,
61 # force a failure
62 "response": False,
63 "requests_response_code": requests.codes.internal_server_error,
64 },
65 ),
66 (
67 "seven://{}/15551232000".format("a" * 25),
68 {
69 "instance": NotifySeven,
70 # throw a bizarre code forcing us to fail to look it up
71 "response": False,
72 "requests_response_code": 999,
73 },
74 ),
75 (
76 "seven://{}/15551232000".format("a" * 25),
77 {
78 "instance": NotifySeven,
79 # Throws a series of i/o exceptions with this flag
80 # is set and tests that we gracefully handle them
81 "test_requests_exceptions": True,
82 },
83 ),
84 (
85 "seven://{}/?to=15551232000".format("a" * 25),
86 {
87 # target phone number using to=
88 "instance": NotifySeven,
89 # Our expected url(privacy=True) startswith() response:
90 "privacy_url": "seven://a...a/15551232000",
91 },
92 ),
93 (
94 "seven://{}/15551".format("a" * 25),
95 {
96 # target phone number invalid
97 "instance": NotifySeven,
98 # Our call to notify() under the hood will fail
99 "notify_response": False,
100 },
101 ),
102 (
103 "seven://{}/15551232000?from=apprise".format("3" * 14),
104 {
105 # valid number, utilizing the optional from= variable
106 "instance": NotifySeven,
107 },
108 ),
109 (
110 "seven://{}/15551232000?source=apprise".format("3" * 14),
111 {
112 # valid number, utilizing the optional source= variable (same as
113 # from)
114 "instance": NotifySeven,
115 },
116 ),
117 (
118 "seven://{}/15551232000?from=apprise&flash=true".format("3" * 14),
119 {
120 # valid number, utilizing the optional from= variable
121 "instance": NotifySeven,
122 },
123 ),
124 (
125 "seven://{}/15551232000?source=apprise&flash=true".format("3" * 14),
126 {
127 # valid number, utilizing the optional source= variable (same as
128 # from)
129 "instance": NotifySeven,
130 },
131 ),
132 (
133 "seven://{}/15551232000?source=AR&flash=1&label=123".format("3" * 14),
134 {
135 # valid number, utilizing the optional source= variable (same as
136 # from)
137 "instance": NotifySeven,
138 },
139 ),
140 )
141
142
143 def test_plugin_seven_urls():
144 """NotifyTemplate() Apprise URLs."""
145
146 # Run our general tests
147 AppriseURLTester(tests=apprise_url_tests).run_all()
148
149
150 @mock.patch("requests.post")
151 def test_plugin_seven_edge_cases(mock_post):
152 """NotifySeven() Edge Cases."""
153
154 # Prepare our response
155 response = requests.Request()
156 response.status_code = requests.codes.ok
157 # Prepare Mock
158 mock_post.return_value = response
159 source = "+1 (555) 123-3456"
160 # No apikey specified
161 with pytest.raises(AppriseImproperlyConfigured):
162 NotifySeven(apikey=None, source=source)