Skip to content

Commit

Permalink
added second test for text based payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Nov 18, 2023
1 parent 9031d3b commit ab71dc7
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/test_plugin_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,50 @@ def test_plugin_discord_notifications(mock_post):
assert 'everyone' in payload['allow_mentions']['parse']
assert 'admin' in payload['allow_mentions']['parse']

# Reset our object
mock_post.reset_mock()

results = NotifyDiscord.parse_url(
f'discord://{webhook_id}/{webhook_token}/?format=text')

assert isinstance(results, dict)
assert results['user'] is None
assert results['webhook_id'] == webhook_id
assert results['webhook_token'] == webhook_token
assert results['password'] is None
assert results['port'] is None
assert results['host'] == webhook_id
assert results['fullpath'] == f'/{webhook_token}/'
assert results['path'] == f'/{webhook_token}/'
assert results['query'] is None
assert results['schema'] == 'discord'
assert results['url'] == f'discord://{webhook_id}/{webhook_token}/'

instance = NotifyDiscord(**results)
assert isinstance(instance, NotifyDiscord)

response = instance.send(body=body)
assert response is True
assert mock_post.call_count == 1

details = mock_post.call_args_list[0]
assert details[0][0] == \
f'https://discord.com/api/webhooks/{webhook_id}/{webhook_token}'

payload = loads(details[1]['data'])

assert 'allow_mentions' in payload
assert 'users' in payload['allow_mentions']
assert len(payload['allow_mentions']['users']) == 1
assert '123' in payload['allow_mentions']['users']
assert 'roles' in payload['allow_mentions']
assert len(payload['allow_mentions']['roles']) == 1
assert '456' in payload['allow_mentions']['roles']
assert 'parse' in payload['allow_mentions']
assert len(payload['allow_mentions']['parse']) == 2
assert 'everyone' in payload['allow_mentions']['parse']
assert 'admin' in payload['allow_mentions']['parse']


@mock.patch('requests.post')
def test_plugin_discord_general(mock_post):
Expand Down

0 comments on commit ab71dc7

Please sign in to comment.