Skip to content

Commit

Permalink
add tests for responding direct messages with at prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
lins05 committed Apr 29, 2015
1 parent 9a87972 commit a4145f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions slackbot/dispatcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf8 -*-
# -*- coding: utf-8 -*-

import logging
import re
Expand Down Expand Up @@ -82,7 +82,7 @@ def filter_text(self, msg):
else:
m = AT_MESSAGE_MATCHER.match(text)
if m:
msg['text'] = m.groups(2)[1]
msg['text'] = m.group(2)
return msg

def loop(self):
Expand Down
13 changes: 9 additions & 4 deletions tests/functional/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ def _wait_for_bot_presense(self, online):
else:
raise AssertionError('test bot is still %s' % ('offline' if online else 'online'))

def send_direct_message(self, msg):
self._send_message_to_bot(self.dm_chan, msg)

def _send_channel_message(self, chan, msg, tobot=True, colon=True):
def _format_message(self, msg, tobot=True, colon=True):
colon = ':' if colon else ''
if tobot:
msg = '<@%s>%s %s' % (self.testbot_userid, colon, msg)
return msg

def send_direct_message(self, msg, tobot=True, colon=True):
msg = self._format_message(msg, tobot, colon)
self._send_message_to_bot(self.dm_chan, msg)

def _send_channel_message(self, chan, msg, tobot=True, colon=True):
msg = self._format_message(msg, tobot, colon)
self._send_message_to_bot(chan, msg)

def send_channel_message(self, msg, tobot=True, colon=True):
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def test_bot_respond_to_simple_message_multiple_plugins(driver):
driver.send_direct_message('hello_formatting hello')
driver.wait_for_bot_direct_messages({'hello sender!', '_hello_ sender!'})

def test_bot_direct_message_with_at_prefix(driver):
driver.send_direct_message('hello', tobot=True)
driver.wait_for_bot_direct_message('hello sender!')
driver.send_direct_message('hello', tobot=True, colon=False)
driver.wait_for_bot_direct_message('hello sender!')

def test_bot_default_reply(driver):
driver.send_direct_message('youdontunderstandthiscommand do you')
driver.wait_for_bot_direct_message('.*You can ask me.*')
Expand Down

0 comments on commit a4145f8

Please sign in to comment.