def test_command_routes_with_different_params_paramless_command_works( 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', '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.command("hello <f_name>") def bar(user, f_name, l_name): return f_name == "mike" @k.command("hello") def moo(user): return True k.start_bot() #assert fake_send_response.assert_called_with(True, "foo")
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_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_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_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
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()