Debian Codegraph @

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