| 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.exception import AppriseImproperlyConfigured |
| 37 |
from apprise.plugins.pagertree import NotifyPagerTree |
| 38 |
|
| 39 |
logging.disable(logging.CRITICAL) |
| 40 |
|
| 41 |
# a test UUID we can use |
| 42 |
INTEGRATION_ID = "int_xxxxxxxxxxx" |
| 43 |
|
| 44 |
# Our Testing URLs |
| 45 |
apprise_url_tests = ( |
| 46 |
( |
| 47 |
"pagertree://", |
| 48 |
{ |
| 49 |
# Missing Integration ID |
| 50 |
"instance": AppriseImproperlyConfigured, |
| 51 |
}, |
| 52 |
), |
| 53 |
# Invalid Integration ID |
| 54 |
( |
| 55 |
"pagertree://%s" % ("+" * 24), |
| 56 |
{ |
| 57 |
"instance": AppriseImproperlyConfigured, |
| 58 |
}, |
| 59 |
), |
| 60 |
# Minimum requirements met |
| 61 |
( |
| 62 |
f"pagertree://{INTEGRATION_ID}", |
| 63 |
{ |
| 64 |
"instance": NotifyPagerTree, |
| 65 |
# Our expected url(privacy=True) startswith() response: |
| 66 |
"privacy_url": "pagertree://i...x?", |
| 67 |
}, |
| 68 |
), |
| 69 |
# change the integration id |
| 70 |
( |
| 71 |
f"pagertree://{INTEGRATION_ID}?integration=int_yyyyyyyyyy", |
| 72 |
{ |
| 73 |
"instance": NotifyPagerTree, |
| 74 |
# Our expected url(privacy=True) startswith() response: |
| 75 |
"privacy_url": "pagertree://i...y?", |
| 76 |
}, |
| 77 |
), |
| 78 |
# entries specified on the URL will over-ride the host (integration id) |
| 79 |
( |
| 80 |
f"pagertree://{INTEGRATION_ID}?id=int_zzzzzzzzzz", |
| 81 |
{ |
| 82 |
"instance": NotifyPagerTree, |
| 83 |
# Our expected url(privacy=True) startswith() response: |
| 84 |
"privacy_url": "pagertree://i...z?", |
| 85 |
}, |
| 86 |
), |
| 87 |
# Integration ID + bad url |
| 88 |
( |
| 89 |
"pagertree://:@/", |
| 90 |
{ |
| 91 |
"instance": AppriseImproperlyConfigured, |
| 92 |
}, |
| 93 |
), |
| 94 |
( |
| 95 |
f"pagertree://{INTEGRATION_ID}", |
| 96 |
{ |
| 97 |
"instance": NotifyPagerTree, |
| 98 |
# force a failure |
| 99 |
"response": False, |
| 100 |
"requests_response_code": requests.codes.internal_server_error, |
| 101 |
}, |
| 102 |
), |
| 103 |
( |
| 104 |
f"pagertree://{INTEGRATION_ID}", |
| 105 |
{ |
| 106 |
"instance": NotifyPagerTree, |
| 107 |
# throw a bizarre code forcing us to fail to look it up |
| 108 |
"response": False, |
| 109 |
"requests_response_code": 999, |
| 110 |
}, |
| 111 |
), |
| 112 |
( |
| 113 |
f"pagertree://{INTEGRATION_ID}", |
| 114 |
{ |
| 115 |
"instance": NotifyPagerTree, |
| 116 |
# Throws a series of i/o exceptions with this flag |
| 117 |
# is set and tests that we gracefully handle them |
| 118 |
"test_requests_exceptions": True, |
| 119 |
}, |
| 120 |
), |
| 121 |
( |
| 122 |
f"pagertree://{INTEGRATION_ID}?urgency=low", |
| 123 |
{ |
| 124 |
# urgency override |
| 125 |
"instance": NotifyPagerTree, |
| 126 |
}, |
| 127 |
), |
| 128 |
( |
| 129 |
f"pagertree://?id={INTEGRATION_ID}&urgency=low", |
| 130 |
{ |
| 131 |
# urgency override and id= (for integration) |
| 132 |
"instance": NotifyPagerTree, |
| 133 |
}, |
| 134 |
), |
| 135 |
( |
| 136 |
f"pagertree://{INTEGRATION_ID}?tags=production,web", |
| 137 |
{ |
| 138 |
# tags |
| 139 |
"instance": NotifyPagerTree, |
| 140 |
}, |
| 141 |
), |
| 142 |
( |
| 143 |
f"pagertree://{INTEGRATION_ID}?action=resolve&thirdparty=123", |
| 144 |
{ |
| 145 |
# test resolve |
| 146 |
"instance": NotifyPagerTree, |
| 147 |
}, |
| 148 |
), |
| 149 |
# Custom values |
| 150 |
( |
| 151 |
f"pagertree://{INTEGRATION_ID}?+pagertree-token=123&:env=prod&-m=v", |
| 152 |
{ |
| 153 |
# minimum requirements and support custom key/value pairs |
| 154 |
"instance": NotifyPagerTree, |
| 155 |
}, |
| 156 |
), |
| 157 |
) |
| 158 |
|
| 159 |
|
| 160 |
def test_plugin_pagertree_urls(): |
| 161 |
"""NotifyPagerTree() Apprise URLs.""" |
| 162 |
|
| 163 |
# Run our general tests |
| 164 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 165 |
|
| 166 |
|
| 167 |
@mock.patch("requests.post") |
| 168 |
def test_plugin_pagertree_general(mock_post): |
| 169 |
"""NotifyPagerTree() General Checks.""" |
| 170 |
|
| 171 |
# Prepare Mock |
| 172 |
mock_post.return_value = requests.Request() |
| 173 |
mock_post.return_value.status_code = requests.codes.ok |
| 174 |
|
| 175 |
# Invalid thirdparty id |
| 176 |
with pytest.raises(AppriseImproperlyConfigured): |
| 177 |
NotifyPagerTree(integration=INTEGRATION_ID, thirdparty=" ") |