Verify that <br/> is properly escapped in telegram calls (#608)

There is no code changes here; but an extra set of unit tests can't hurt.
This commit is contained in:
Chris Caron 2022-06-30 17:47:06 -04:00 committed by GitHub
parent 4c57d76ee7
commit 1519e98cda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -792,6 +792,93 @@ def test_plugin_telegram_formating_py3(mock_post):
'# A Great Title\r\n_[Apprise Body Title](http://localhost)_ had ' \
'[a change](http://127.0.0.2)'
# Reset our values
mock_post.reset_mock()
#
# Now test that <br/> is correctly escaped
#
title = 'Test Message Title'
body = 'Test Message Body <br/> ok</br>'
aobj = Apprise()
aobj.add('tgram://1234:aaaaaaaaa/-1123456245134')
assert len(aobj) == 1
assert aobj.notify(
title=title, body=body, body_format=NotifyFormat.MARKDOWN)
# Test our calls
assert mock_post.call_count == 1
assert mock_post.call_args_list[0][0][0] == \
'https://api.telegram.org/bot1234:aaaaaaaaa/sendMessage'
payload = loads(mock_post.call_args_list[0][1]['data'])
# Test that everything is escaped properly in a HTML mode
assert payload['text'] == \
'<b>Test Message Title\r\n' \
'</b>\r\n' \
'Test Message Body\r\n' \
'ok\r\n'
# Reset our values
mock_post.reset_mock()
#
# Now test that <br/> is correctly escaped as it would have been via the
# CLI mode where the body_format is TEXT
#
aobj = Apprise()
aobj.add('tgram://1234:aaaaaaaaa/-1123456245134')
assert len(aobj) == 1
assert aobj.notify(
title=title, body=body, body_format=NotifyFormat.TEXT)
# Test our calls
assert mock_post.call_count == 1
assert mock_post.call_args_list[0][0][0] == \
'https://api.telegram.org/bot1234:aaaaaaaaa/sendMessage'
payload = loads(mock_post.call_args_list[0][1]['data'])
# Test that everything is escaped properly in a HTML mode
assert payload['text'] == \
'<b>Test Message Title</b>\r\n' \
'Test Message Body &lt;br/&gt; ok&lt;/br&gt;'
# Reset our values
mock_post.reset_mock()
#
# Now test that <br/> is correctly escaped if fed as HTML
#
aobj = Apprise()
aobj.add('tgram://1234:aaaaaaaaa/-1123456245134')
assert len(aobj) == 1
assert aobj.notify(
title=title, body=body, body_format=NotifyFormat.HTML)
# Test our calls
assert mock_post.call_count == 1
assert mock_post.call_args_list[0][0][0] == \
'https://api.telegram.org/bot1234:aaaaaaaaa/sendMessage'
payload = loads(mock_post.call_args_list[0][1]['data'])
# Test that everything is escaped properly in a HTML mode
assert payload['text'] == \
'<b>Test Message Title</b>\r\n' \
'Test Message Body\r\n' \
'ok\r\n'
@pytest.mark.skipif(sys.version_info.major >= 3, reason="Requires Python 2.x+")
@mock.patch('requests.post')
@ -1094,6 +1181,93 @@ def test_plugin_telegram_formating_py2(mock_post):
'# A Great Title\r\n_[Apprise Body Title](http://localhost)_ had ' \
'[a change](http://127.0.0.2)'
# Reset our values
mock_post.reset_mock()
#
# Now test that <br/> is correctly escaped
#
title = 'Test Message Title'
body = 'Test Message Body <br/> ok</br>'
aobj = Apprise()
aobj.add('tgram://1234:aaaaaaaaa/-1123456245134')
assert len(aobj) == 1
assert aobj.notify(
title=title, body=body, body_format=NotifyFormat.MARKDOWN)
# Test our calls
assert mock_post.call_count == 1
assert mock_post.call_args_list[0][0][0] == \
'https://api.telegram.org/bot1234:aaaaaaaaa/sendMessage'
payload = loads(mock_post.call_args_list[0][1]['data'])
# Test that everything is escaped properly in a HTML mode
assert payload['text'] == \
'<b>Test Message Title\r\n' \
'</b>\r\n' \
'Test Message Body\r\n' \
'ok\r\n'
# Reset our values
mock_post.reset_mock()
#
# Now test that <br/> is correctly escaped as it would have been via the
# CLI mode where the body_format is TEXT
#
aobj = Apprise()
aobj.add('tgram://1234:aaaaaaaaa/-1123456245134')
assert len(aobj) == 1
assert aobj.notify(
title=title, body=body, body_format=NotifyFormat.TEXT)
# Test our calls
assert mock_post.call_count == 1
assert mock_post.call_args_list[0][0][0] == \
'https://api.telegram.org/bot1234:aaaaaaaaa/sendMessage'
payload = loads(mock_post.call_args_list[0][1]['data'])
# Test that everything is escaped properly in a HTML mode
assert payload['text'] == \
'<b>Test Message Title</b>\r\n' \
'Test Message Body &lt;br/&gt; ok&lt;/br&gt;'
# Reset our values
mock_post.reset_mock()
#
# Now test that <br/> is correctly escaped if fed as HTML
#
aobj = Apprise()
aobj.add('tgram://1234:aaaaaaaaa/-1123456245134')
assert len(aobj) == 1
assert aobj.notify(
title=title, body=body, body_format=NotifyFormat.HTML)
# Test our calls
assert mock_post.call_count == 1
assert mock_post.call_args_list[0][0][0] == \
'https://api.telegram.org/bot1234:aaaaaaaaa/sendMessage'
payload = loads(mock_post.call_args_list[0][1]['data'])
# Test that everything is escaped properly in a HTML mode
assert payload['text'] == \
'<b>Test Message Title</b>\r\n' \
'Test Message Body\r\n' \
'ok\r\n'
@mock.patch('requests.post')
def test_plugin_telegram_html_formatting(mock_post):