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 commit bc6120907e.

* Revert "Slack: drop unused validate_certs option"

This reverts commit a981ee6bca.

* 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:
Lee Goolsbee 2020-07-29 15:11:32 -05:00 committed by GitHub
parent 08f10d5758
commit 9822d8172b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 8 deletions

View file

@ -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({