def test_command_decorator_invokes_function_with_multiple_parameter( fake_env_get, fake_api_call, fake_rtm_connect, fake_rtm_read, fake_running, fake_get_sleep_time, fake_send_response): #arrange reset_count() fake_running.side_effect = fake_runner fake_get_sleep_time.return_value = 0 fake_message = [{ 'text': 'hello bob smith', 'channel': 'foo', 'user': '******' }] fake_rtm_read.return_value = fake_message fake_rtm_connect.return_value = True fake_api_call.side_effect = api_call_side_effect #act k = Kairo("app") @k.command("hello <f_name> <l_name>") def foo(user, f_name, l_name): return f_name == "bob" and l_name == "smith" k.start_bot() #assert fake_send_response.assert_called_with(True, "foo")
def test_parse_slack_message_returns_user_from_message(): #arrange fake_message = [{'text': 'test 123', 'channel': 'foo', 'user': '******'}] k = Kairo("app") #act message, channel, user = k.parse_slack_message(fake_message) #assert assert 'bar' == user
def test_send_response_calls_slack_client_api_call(fake_api_call): k = Kairo("app") k.slack_client = SlackClient( "fake_token" ) #slack_client is instantiated in start_bot, calling this even to avoid mocking everything else. k.send_response("text1", "channel2") fake_api_call.assert_called_with("chat.postMessage", channel="channel2", text="text1", as_user=True)
def test_get_user_name_by_id_returns_username(fake_api_call, fake_rtm_connect, fake_rtm_read, fake_running, fake_get_sleep_time): #arrange k = Kairo("app") fake_api_call.side_effect = api_call_side_effect fake_get_sleep_time.return_value = 0 reset_count() fake_running.side_effect = fake_runner fake_rtm_read.return_value = [{ 'text': 'test 123', 'channel': 'foo', 'user': '******' }] #act k.start_bot("fake_token") name = k.get_user_name_by_id("1234") #assert assert name == "fake_bot"
def test_command_decorator_invokes_function(fake_env_get, fake_api_call, fake_rtm_connect, fake_rtm_read, fake_running, fake_get_sleep_time, fake_send_response): #arrange reset_count() fake_running.side_effect = fake_runner fake_get_sleep_time.return_value = 0 fake_message = [{'text': 'hello bob', 'channel': 'foo', 'user': '******'}] fake_rtm_read.return_value = fake_message fake_rtm_connect.return_value = True fake_api_call.side_effect = api_call_side_effect #act k = Kairo("app") @k.command("hello <name>") def foo(user, name): return "bar bar" k.start_bot() #assert fake_send_response.assert_called_with('bar bar', 'foo')
def test_command_decorator_is_parsed(fake_env_get, fake_api_call, fake_rtm_connect, fake_rtm_read, fake_running, fake_get_sleep_time, fake_parse_slack_message, capsys): #arrange reset_count() fake_running.side_effect = fake_runner fake_get_sleep_time.return_value = 0 fake_message = [{'text': 'test 123', 'channel': 'foo', 'user': '******'}] fake_rtm_read.return_value = fake_message fake_rtm_connect.return_value = True fake_parse_slack_message.return_value = None, None, None fake_api_call.side_effect = api_call_side_effect #act k = Kairo("app") k.start_bot() @k.command("hello <name>") def foo(): return True #assert assert "hello1" in k.commands
def test_Kairo_allows_to_specific_env_var_name(fake_env_get, fake_api_call, fake_rtm_connect, fake_rtm_read, fake_running, fake_get_sleep_time): #arrange reset_count() fake_running.side_effect = fake_runner fake_token_name = 'my_env_var' fake_api_call.side_effect = api_call_side_effect fake_rtm_read.return_value = [{ 'text': 'test 123', 'channel': 'foo', 'user': '******' }] fake_rtm_connect.return_value = True fake_get_sleep_time.return_value = 0 #act k = Kairo("app") k.load_token_from_env(name=fake_token_name) k.start_bot() #assert fake_env_get.assert_called_with(fake_token_name)
def test_Kairo_has_slack_client_member(): #arrange k = Kairo("app") #assert assert k.slack_client is None
def test_Kairo_has_users_member(): #arrange k = Kairo("app") #assert assert k.users is None
def test_parse_slack_message_with_none_passed_returns_none_tuple(): k = Kairo("app") command, channel, user = k.parse_slack_message(None) assert command is None assert channel is None assert user is None
def test_Kairo_takes_name(): k = Kairo("app") assert True
def test_running_returns_true(): #arrange k = Kairo("app") running = k.running() #assert assert running == 1
def test_get_sleep_time_returns_one(fake_api_call): #arrange k = Kairo("app") sleep_time = k.get_sleep_time() #assert assert sleep_time == 1
from kairo import Kairo k = Kairo("app") @k.command("hello <f_name> <l_name>") def foo(user,f_name,l_name): return "Hello {f_name} {l_name}, it's nice to meet you!".format(f_name=f_name,l_name=l_name) k.start_bot()