mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 10:40:22 -07:00
slack: support for blocks (#702)
* Slack: add support for blocks * Slack: drop unused validate_certs option * Slack: update docs to reflect thread_id can be sent with tokens other than WebAPI * Slack: drop escaping of quotes and apostrophes * Slack: typo * Revert "Slack: drop escaping of quotes and apostrophes" This reverts commitbc6120907e
. * Revert "Slack: drop unused validate_certs option" This reverts commita981ee6bca
. * Slack: other/minor PR feedback * Slack: add changelog fragment * Slack: clean-up/clarify use of recursive escaping function * Slack: PR feedback Co-authored-by: Lee Goolsbee <lgoolsbee@atlassian.com>
This commit is contained in:
parent
08f10d5758
commit
9822d8172b
3 changed files with 100 additions and 8 deletions
|
@ -88,6 +88,43 @@ class TestSlackModule(ModuleTestCase):
|
|||
assert call_data['thread_ts'] == '100.00'
|
||||
assert fetch_url_mock.call_args[1]['url'] == "https://hooks.slack.com/services/XXXX/YYYY/ZZZZ"
|
||||
|
||||
def test_message_with_blocks(self):
|
||||
"""tests sending a message with blocks"""
|
||||
set_module_args({
|
||||
'token': 'XXXX/YYYY/ZZZZ',
|
||||
'msg': 'test',
|
||||
'blocks': [{
|
||||
'type': 'section',
|
||||
'text': {
|
||||
'type': 'mrkdwn',
|
||||
'text': '*test*'
|
||||
},
|
||||
'accessory': {
|
||||
'type': 'image',
|
||||
'image_url': 'https://www.ansible.com/favicon.ico',
|
||||
'alt_text': 'test'
|
||||
}
|
||||
}, {
|
||||
'type': 'section',
|
||||
'text': {
|
||||
'type': 'plain_text',
|
||||
'text': 'test',
|
||||
'emoji': True
|
||||
}
|
||||
}]
|
||||
})
|
||||
|
||||
with patch.object(slack, "fetch_url") as fetch_url_mock:
|
||||
fetch_url_mock.return_value = (None, {"status": 200})
|
||||
with self.assertRaises(AnsibleExitJson):
|
||||
self.module.main()
|
||||
|
||||
self.assertTrue(fetch_url_mock.call_count, 1)
|
||||
call_data = json.loads(fetch_url_mock.call_args[1]['data'])
|
||||
assert call_data['username'] == "Ansible"
|
||||
assert call_data['blocks'][1]['text']['text'] == "test"
|
||||
assert fetch_url_mock.call_args[1]['url'] == "https://hooks.slack.com/services/XXXX/YYYY/ZZZZ"
|
||||
|
||||
def test_message_with_invalid_color(self):
|
||||
"""tests sending invalid color value to module"""
|
||||
set_module_args({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue