aboutsummaryrefslogtreecommitdiffstats
path: root/_pytest/test_topic_command.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2017-10-08 23:58:33 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-10-08 23:59:20 +0200
commitd1a2abb989f3e769be84e16ee782c6927119ba58 (patch)
tree74def7e156b7acc3d30f34f92a3bc7321623454a /_pytest/test_topic_command.py
parentb8d4a3375d105a22aa3d90a199ecf9a8ff16e5b6 (diff)
downloadwee-slack-d1a2abb989f3e769be84e16ee782c6927119ba58.tar.gz
test: Add tests for topic_command_cb
Diffstat (limited to '_pytest/test_topic_command.py')
-rw-r--r--_pytest/test_topic_command.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/_pytest/test_topic_command.py b/_pytest/test_topic_command.py
index 2a4f069..9d9a35e 100644
--- a/_pytest/test_topic_command.py
+++ b/_pytest/test_topic_command.py
@@ -1,4 +1,6 @@
-from wee_slack import parse_topic_command
+import wee_slack
+from wee_slack import parse_topic_command, topic_command_cb
+from mock import patch
def test_parse_topic_without_arguments():
@@ -42,3 +44,53 @@ def test_parse_topic_with_channel_and_delete():
assert channel_name == 'general'
assert topic == ''
+
+
+def test_call_topic_without_arguments(realish_eventrouter):
+ team = realish_eventrouter.teams.values()[-1]
+ channel = team.channels.values()[-1]
+ current_buffer = channel.channel_buffer
+ wee_slack.EVENTROUTER = realish_eventrouter
+
+ command = '/topic'
+
+ with patch('wee_slack.w.prnt') as fake_prnt:
+ result = topic_command_cb(None, current_buffer, command)
+ fake_prnt.assert_called_with(
+ channel.channel_buffer,
+ 'Topic for {} is "{}"'.format(channel.name, channel.topic),
+ )
+ assert result == wee_slack.w.WEECHAT_RC_OK_EAT
+
+
+def test_call_topic_with_unknown_channel(realish_eventrouter):
+ team = realish_eventrouter.teams.values()[-1]
+ channel = team.channels.values()[-1]
+ current_buffer = channel.channel_buffer
+ wee_slack.EVENTROUTER = realish_eventrouter
+
+ command = '/topic #nonexisting'
+
+ with patch('wee_slack.w.prnt') as fake_prnt:
+ result = topic_command_cb(None, current_buffer, command)
+ fake_prnt.assert_called_with(
+ team.channel_buffer,
+ "#nonexisting: No such channel",
+ )
+ assert result == wee_slack.w.WEECHAT_RC_OK_EAT
+
+
+def test_call_topic_with_channel_and_string(realish_eventrouter):
+ team = realish_eventrouter.teams.values()[-1]
+ channel = team.channels.values()[-1]
+ current_buffer = channel.channel_buffer
+ wee_slack.EVENTROUTER = realish_eventrouter
+
+ command = '/topic #general new topic'
+
+ result = topic_command_cb(None, current_buffer, command)
+ request = realish_eventrouter.queue[-1]
+ assert request.request == 'channels.setTopic'
+ assert request.post_data == {
+ 'channel': 'C407ABS94', 'token': 'xoxoxoxox', 'topic': 'new topic'}
+ assert result == wee_slack.w.WEECHAT_RC_OK_EAT