CLI --interpret-escapes works without --title specified (#471)

pull/475/head
Chris Caron 2021-10-30 17:00:05 -04:00 committed by GitHub
parent 245e57cca9
commit 9b5815ef6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 18 deletions

View File

@ -558,6 +558,7 @@ class Apprise(object):
logger.error('Failed to escape message body') logger.error('Failed to escape message body')
raise TypeError raise TypeError
if title:
try: try:
# Added overhead required due to Python 3 Encoding Bug # Added overhead required due to Python 3 Encoding Bug
# identified here: https://bugs.python.org/issue21331 # identified here: https://bugs.python.org/issue21331
@ -566,8 +567,9 @@ class Apprise(object):
.decode('unicode-escape') .decode('unicode-escape')
except UnicodeDecodeError: # pragma: no cover except UnicodeDecodeError: # pragma: no cover
# This occurs using a very old verion of Python 2.7 such # This occurs using a very old verion of Python 2.7
# as the one that ships with CentOS/RedHat 7.x (v2.7.5). # such as the one that ships with CentOS/RedHat 7.x
# (v2.7.5).
title = title.decode('string_escape') title = title.decode('string_escape')
except AttributeError: except AttributeError:

View File

@ -576,6 +576,23 @@ def test_apprise_cli_nux_env(tmpdir):
]) ])
assert result.exit_code == 1 assert result.exit_code == 1
# Test Escaping:
result = runner.invoke(cli.main, [
'-e',
'-t', 'test\ntitle',
'-b', 'test\nbody',
'good://localhost',
])
assert result.exit_code == 0
# Test Escaping (without title)
result = runner.invoke(cli.main, [
'--interpret-escapes',
'-b', 'test\nbody',
'good://localhost',
])
assert result.exit_code == 0
@mock.patch('platform.system') @mock.patch('platform.system')
def test_apprise_cli_windows_env(mock_system): def test_apprise_cli_windows_env(mock_system):

View File

@ -191,13 +191,13 @@ def test_apprise_escaping_py3(mock_post):
# the body only. Now we run similar tests but only make the title # the body only. Now we run similar tests but only make the title
# bad and always mark the body good # bad and always mark the body good
assert a.notify( assert a.notify(
title=None, body="valid", interpret_escapes=True) is False title=None, body="valid", interpret_escapes=True) is True
assert a.notify( assert a.notify(
title=4, body="valid", interpret_escapes=True) is False title=4, body="valid", interpret_escapes=True) is False
assert a.notify( assert a.notify(
title=object(), body="valid", interpret_escapes=True) is False title=object(), body="valid", interpret_escapes=True) is False
assert a.notify( assert a.notify(
title=False, body="valid", interpret_escapes=True) is False title=False, body="valid", interpret_escapes=True) is True
assert a.notify( assert a.notify(
title=b'byte title', body="valid", interpret_escapes=True) is False title=b'byte title', body="valid", interpret_escapes=True) is False
@ -320,10 +320,10 @@ def test_apprise_escaping_py2(mock_post):
# the body only. Now we run similar tests but only make the title # the body only. Now we run similar tests but only make the title
# bad and always mark the body good # bad and always mark the body good
assert a.notify( assert a.notify(
title=None, body="valid", interpret_escapes=True) is False title=None, body="valid", interpret_escapes=True) is True
assert a.notify( assert a.notify(
title=4, body="valid", interpret_escapes=True) is False title=4, body="valid", interpret_escapes=True) is False
assert a.notify( assert a.notify(
title=object(), body="valid", interpret_escapes=True) is False title=object(), body="valid", interpret_escapes=True) is False
assert a.notify( assert a.notify(
title=False, body="valid", interpret_escapes=True) is False title=False, body="valid", interpret_escapes=True) is True