def test_slackbot_send_text(): from rasa_core.channels.slack import SlackBot httpretty.register_uri(httpretty.POST, 'https://slack.com/api/chat.postMessage', body='{"ok":true,"purpose":"Testing bots"}') httpretty.enable() bot = SlackBot("DummyToken", "General") bot.send_text_message("ID", "my message") httpretty.disable() r = httpretty.latest_requests[-1] assert r.parsed_body == {'as_user': ['True'], 'channel': ['General'], 'text': ['my message']}
def test_slackbot_send_attachment_withtext(): from rasa_core.channels.slack import SlackBot httpretty.register_uri(httpretty.POST, 'https://slack.com/api/chat.postMessage', body='{"ok":true,"purpose":"Testing bots"}') httpretty.enable() bot = SlackBot("DummyToken", "General") text = "Sample text" attachment = json.dumps([{"fallback": "Financial Advisor Summary", "color": "#36a64f", "author_name": "ABE", "title": "Financial Advisor Summary", "title_link": "http://tenfactorialrocks.com", "image_url": "https://r.com/cancel/r12", "thumb_url": "https://r.com/cancel/r12", "actions": [{"type": "button", "text": "\ud83d\udcc8 Dashboard", "url": "https://r.com/cancel/r12", "style": "primary"}, {"type": "button", "text": "\ud83d\udccb XL", "url": "https://r.com/cancel/r12", "style": "danger"}, {"type": "button", "text": "\ud83d\udce7 E-Mail", "url": "https://r.com/cancel/r123", "style": "danger"}], "footer": "Powered by 1010rocks", "ts": 1531889719}]) bot.send_attachment("ID", attachment, text) httpretty.disable() r = httpretty.latest_requests[-1] assert r.parsed_body == {'channel': ['General'], 'as_user': ['True'], 'text': ['Sample text'], 'attachments': [attachment]}
def test_slackbot_send_text(): from rasa_core.channels.slack import SlackBot httpretty.register_uri(httpretty.POST, 'https://slack.com/api/chat.postMessage', body='{"ok":true,"purpose":"Testing bots"}') httpretty.enable() bot = SlackBot("DummyToken", "General") bot.send_text_message("ID", "my message") httpretty.disable() r = httpretty.latest_requests[-1] assert r.parsed_body == { 'as_user': ['True'], 'channel': ['General'], 'text': ['my message'] }
def test_slackbot_send_image_url(): from rasa_core.channels.slack import SlackBot httpretty.register_uri(httpretty.POST, 'https://slack.com/api/chat.postMessage', body='{"ok":true,"purpose":"Testing bots"}') httpretty.enable() bot = SlackBot("DummyToken", "General") url = json.dumps([{"URL": "http://www.rasa.net"}]) bot.send_image_url("ID", url) httpretty.disable() r = httpretty.latest_requests[-1] assert r.parsed_body['as_user'] == ['True'] assert r.parsed_body['channel'] == ['General'] assert len(r.parsed_body['attachments']) == 1 assert '"text": ""' in r.parsed_body['attachments'][0] assert '"image_url": "[{\\"URL\\": \\"http://www.rasa.net\\"}]"' \ in r.parsed_body['attachments'][0]
def test_slackbot_init_two_parameter(): from rasa_core.channels.slack import SlackBot bot = SlackBot("DummyToken", "General") assert bot.token == "DummyToken" assert bot.slack_channel == "General"
def test_slackbot_init_one_parameter(): from rasa_core.channels.slack import SlackBot ch = SlackBot("DummyToken") assert ch.token == "DummyToken" assert ch.slack_channel is None