Exclusive Apprise URL Tag matching (#154)

This commit is contained in:
Chris Caron
2019-09-29 18:19:55 -04:00
committed by GitHub
parent 1d84f7fd8a
commit 7f60fff521
11 changed files with 468 additions and 152 deletions

View File

@ -23,6 +23,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from __future__ import print_function
import re
import mock
from apprise import cli
from apprise import NotifyBase
@ -59,21 +60,21 @@ def test_apprise_cli(tmpdir):
# Pretend everything is okay
return True
def url(self):
def url(self, *args, **kwargs):
# Support url()
return ''
return 'good://'
class BadNotification(NotifyBase):
def __init__(self, *args, **kwargs):
super(BadNotification, self).__init__(*args, **kwargs)
def notify(self, **kwargs):
# Pretend everything is okay
# Force a notification failure
return False
def url(self):
def url(self, *args, **kwargs):
# Support url()
return ''
return 'bad://'
# Set up our notification types
SCHEMA_MAP['good'] = GoodNotification
@ -120,6 +121,16 @@ def test_apprise_cli(tmpdir):
])
assert result.exit_code == 1
# Testing with the --dry-run flag reveals a successful response since we
# don't actually execute the bad:// notification; we only display it
result = runner.invoke(cli.main, [
'-t', 'test title',
'-b', 'test body',
'bad://localhost',
'--dry-run',
])
assert result.exit_code == 0
# Write a simple text based configuration file
t = tmpdir.mkdir("apprise-obj").join("apprise")
buf = """
@ -128,13 +139,14 @@ def test_apprise_cli(tmpdir):
"""
t.write(buf)
# This will read our configuration and send 2 notices to
# each of the above defined good:// entries
# This will read our configuration and not send any notices at all
# because we assigned tags to all of our urls and didn't identify
# a specific match below.
result = runner.invoke(cli.main, [
'-b', 'test config',
'--config', str(t),
])
assert result.exit_code == 0
assert result.exit_code == 2
# This will send out 1 notification because our tag matches
# one of the entries above
@ -146,17 +158,6 @@ def test_apprise_cli(tmpdir):
])
assert result.exit_code == 0
# This will send out 0 notification because our tag requests that we meet
# at least 2 tags associated with the same notification service (which
# isn't the case above)
# translation: has taga AND tagd
result = runner.invoke(cli.main, [
'-b', 'has taga AND tagd',
'--config', str(t),
'--tag', 'taga,tagd',
])
assert result.exit_code == 0
# This will send out 2 notifications because by specifying 2 tag
# entries, we 'or' them together:
# translation: has taga or tagb or tagd
@ -169,6 +170,81 @@ def test_apprise_cli(tmpdir):
])
assert result.exit_code == 0
# Write a simple text based configuration file
t = tmpdir.mkdir("apprise-obj2").join("apprise-test2")
buf = """
good://localhost/1
good://localhost/2
good://localhost/3
good://localhost/4
good://localhost/5
myTag=good://localhost/6
"""
t.write(buf)
# This will read our configuration and send a notification to
# the first 5 entries in the list, but not the one that has
# the tag associated with it
result = runner.invoke(cli.main, [
'-b', 'test config',
'--config', str(t),
])
assert result.exit_code == 0
# As a way of ensuring we match the first 5 entries, we can run a
# --dry-run against the same result set above and verify the output
result = runner.invoke(cli.main, [
'-b', 'test config',
'--config', str(t),
'--dry-run',
])
assert result.exit_code == 0
lines = re.split(r'[\r\n]', result.output.strip())
# 5 lines of all good:// entries matched
assert len(lines) == 5
# Verify we match against the remaining good:// entries
for i in range(0, 5):
assert lines[i].endswith('good://')
# This will fail because nothing matches mytag. It's case sensitive
# and we would only actually match against myTag
result = runner.invoke(cli.main, [
'-b', 'has taga',
'--config', str(t),
'--tag', 'mytag',
])
assert result.exit_code == 2
# Same command as the one identified above except we set the --dry-run
# flag. This causes our list of matched results to be printed only.
# However, since we don't match anything; we still fail with a return code
# of 2.
result = runner.invoke(cli.main, [
'-b', 'has taga',
'--config', str(t),
'--tag', 'mytag',
'--dry-run'
])
assert result.exit_code == 2
# Here is a case where we get what was expected
result = runner.invoke(cli.main, [
'-b', 'has taga',
'--config', str(t),
'--tag', 'myTag',
])
assert result.exit_code == 0
# Testing with the --dry-run flag reveals the same positive results
# because there was at least one match
result = runner.invoke(cli.main, [
'-b', 'has taga',
'--config', str(t),
'--tag', 'myTag',
'--dry-run',
])
assert result.exit_code == 0
@mock.patch('platform.system')
def test_apprise_cli_windows_env(mock_system):