mirror of
https://github.com/caronc/apprise.git
synced 2025-08-09 08:25:07 +02:00
Discord Attachment Support
This commit is contained in:
@ -3849,125 +3849,6 @@ def test_notify_boxcar_plugin(mock_post, mock_get):
|
||||
assert len(p.device_tokens) == 3
|
||||
|
||||
|
||||
@mock.patch('requests.get')
|
||||
@mock.patch('requests.post')
|
||||
def test_notify_discord_plugin(mock_post, mock_get):
|
||||
"""
|
||||
API: NotifyDiscord() Extra Checks
|
||||
|
||||
"""
|
||||
# Disable Throttling to speed testing
|
||||
plugins.NotifyBase.request_rate_per_sec = 0
|
||||
|
||||
# Initialize some generic (but valid) tokens
|
||||
webhook_id = 'A' * 24
|
||||
webhook_token = 'B' * 64
|
||||
|
||||
# Prepare Mock
|
||||
mock_get.return_value = requests.Request()
|
||||
mock_post.return_value = requests.Request()
|
||||
mock_post.return_value.status_code = requests.codes.ok
|
||||
mock_get.return_value.status_code = requests.codes.ok
|
||||
|
||||
# Invalid webhook id
|
||||
with pytest.raises(TypeError):
|
||||
plugins.NotifyDiscord(webhook_id=None, webhook_token=webhook_token)
|
||||
# Invalid webhook id (whitespace)
|
||||
with pytest.raises(TypeError):
|
||||
plugins.NotifyDiscord(webhook_id=" ", webhook_token=webhook_token)
|
||||
|
||||
# Invalid webhook token
|
||||
with pytest.raises(TypeError):
|
||||
plugins.NotifyDiscord(webhook_id=webhook_id, webhook_token=None)
|
||||
# Invalid webhook token (whitespace)
|
||||
with pytest.raises(TypeError):
|
||||
plugins.NotifyDiscord(webhook_id=webhook_id, webhook_token=" ")
|
||||
|
||||
obj = plugins.NotifyDiscord(
|
||||
webhook_id=webhook_id,
|
||||
webhook_token=webhook_token,
|
||||
footer=True, thumbnail=False)
|
||||
|
||||
# This call includes an image with it's payload:
|
||||
assert obj.notify(
|
||||
body='body', title='title', notify_type=NotifyType.INFO) is True
|
||||
|
||||
# Test our header parsing
|
||||
test_markdown = "## Heading one\nbody body\n\n" + \
|
||||
"# Heading 2 ##\n\nTest\n\n" + \
|
||||
"more content\n" + \
|
||||
"even more content \t\r\n\n\n" + \
|
||||
"# Heading 3 ##\n\n\n" + \
|
||||
"normal content\n" + \
|
||||
"# heading 4\n" + \
|
||||
"#### Heading 5"
|
||||
|
||||
results = obj.extract_markdown_sections(test_markdown)
|
||||
assert isinstance(results, list) is True
|
||||
# We should have 5 sections (since there are 5 headers identified above)
|
||||
assert len(results) == 5
|
||||
assert results[0]['name'] == 'Heading one'
|
||||
assert results[0]['value'] == '```md\nbody body\n```'
|
||||
assert results[1]['name'] == 'Heading 2'
|
||||
assert results[1]['value'] == \
|
||||
'```md\nTest\n\nmore content\neven more content\n```'
|
||||
assert results[2]['name'] == 'Heading 3'
|
||||
assert results[2]['value'] == \
|
||||
'```md\nnormal content\n```'
|
||||
assert results[3]['name'] == 'heading 4'
|
||||
assert results[3]['value'] == '```md\n\n```'
|
||||
assert results[4]['name'] == 'Heading 5'
|
||||
assert results[4]['value'] == '```md\n\n```'
|
||||
|
||||
# Test our markdown
|
||||
obj = Apprise.instantiate(
|
||||
'discord://{}/{}/?format=markdown'.format(webhook_id, webhook_token))
|
||||
assert isinstance(obj, plugins.NotifyDiscord)
|
||||
assert obj.notify(
|
||||
body=test_markdown, title='title', notify_type=NotifyType.INFO) is True
|
||||
|
||||
# Empty String
|
||||
results = obj.extract_markdown_sections("")
|
||||
assert isinstance(results, list) is True
|
||||
assert len(results) == 0
|
||||
|
||||
# String without Heading
|
||||
test_markdown = "Just a string without any header entries.\n" + \
|
||||
"A second line"
|
||||
results = obj.extract_markdown_sections(test_markdown)
|
||||
assert isinstance(results, list) is True
|
||||
assert len(results) == 0
|
||||
|
||||
# Use our test markdown string during a notification
|
||||
assert obj.notify(
|
||||
body=test_markdown, title='title', notify_type=NotifyType.INFO) is True
|
||||
|
||||
# Create an apprise instance
|
||||
a = Apprise()
|
||||
|
||||
# Our processing is slightly different when we aren't using markdown
|
||||
# as we do not pre-parse content during our notifications
|
||||
assert a.add(
|
||||
'discord://{webhook_id}/{webhook_token}/'
|
||||
'?format=markdown&footer=Yes'.format(
|
||||
webhook_id=webhook_id,
|
||||
webhook_token=webhook_token)) is True
|
||||
|
||||
# This call includes an image with it's payload:
|
||||
assert a.notify(body=test_markdown, title='title',
|
||||
notify_type=NotifyType.INFO,
|
||||
body_format=NotifyFormat.TEXT) is True
|
||||
|
||||
assert a.notify(body=test_markdown, title='title',
|
||||
notify_type=NotifyType.INFO,
|
||||
body_format=NotifyFormat.MARKDOWN) is True
|
||||
|
||||
# Toggle our logo availability
|
||||
a.asset.image_url_logo = None
|
||||
assert a.notify(
|
||||
body='body', title='title', notify_type=NotifyType.INFO) is True
|
||||
|
||||
|
||||
@mock.patch('requests.get')
|
||||
@mock.patch('requests.post')
|
||||
def test_notify_emby_plugin_login(mock_post, mock_get):
|
||||
|
Reference in New Issue
Block a user