def test_start_if_running(self): quest = MagicMock() quest.start_quest.return_value = [] bot_logic = BotLogic(quest) bot_logic.is_started = True bot_logic.start() self.assertEqual(bot_logic.is_started, True) quest.start_quest.assert_not_called()
def test_help_if_not_running(self): quest = MagicMock() bot_logic = BotLogic(quest) bot_logic.is_started = False messages_list = bot_logic.help() self.assertEqual(bot_logic.is_started, False) self.assertEqual(messages_list[0].text, bot_logic.messages['help']) self.assertEqual(len(messages_list), 1)
def test_stop_if_running(self): quest = MagicMock() quest.end_quest.return_value = [] bot_logic = BotLogic(quest) bot_logic.is_started = True bot_logic.stop() self.assertEqual(bot_logic.is_started, False) quest.end_quest.assert_called_once()
def test_send_messages_none_messages_list(self): quest = MagicMock() update = MagicMock() context = MagicMock() messages_list = None bot_logic = BotLogic(quest) with self.assertRaises(AttributeError): bot_logic.send_messages(update, context, messages_list)
def test_hint_if_running(self): quest = MagicMock() quest.get_hint.return_value = [] bot_logic = BotLogic(quest) bot_logic.is_started = True bot_logic.hint() self.assertEqual(bot_logic.is_started, True) quest.get_hint.assert_called_once()
def test_answer_if_running(self): quest = MagicMock() quest.assess_answer.return_value = [] answer_text = 'abc' bot_logic = BotLogic(quest) bot_logic.is_started = True bot_logic.answer(answer_text) self.assertEqual(bot_logic.is_started, True) quest.assess_answer.assert_called_once()
def test_handle_message_answer(self): quest = MagicMock() update = MagicMock() update.message.text = 'abc' context = MagicMock() bot_logic = BotLogic(quest) bot_logic.answer = MagicMock(return_value=[]) bot_logic.handle_message(update, context) bot_logic.answer.assert_called_once()
def test_send_messages_empty_messages_list(self): quest = MagicMock() update = MagicMock() context = MagicMock() context.bot.send_message.return_value = None messages_list = [] bot_logic = BotLogic(quest) bot_logic.send_messages(update, context, messages_list) context.bot.send_message.assert_not_called()
def test_handle_message_help(self): quest = MagicMock() update = MagicMock() update.message.text = '/help' context = MagicMock() bot_logic = BotLogic(quest) bot_logic.help = MagicMock(return_value=[]) bot_logic.handle_message(update, context) bot_logic.help.assert_called_once()
def test_hint_if_not_running(self): quest = MagicMock() quest.get_hint.return_value = [] bot_logic = BotLogic(quest) bot_logic.is_started = False messages_list = bot_logic.hint() self.assertEqual(bot_logic.is_started, False) quest.get_hint.assert_not_called() self.assertEqual(messages_list[0].text, bot_logic.messages['bot_not_started']) self.assertEqual(len(messages_list), 1)
def test_answer_if_not_running(self): quest = MagicMock() quest.assess_answer.return_value = [] answer_text = 'abc' bot_logic = BotLogic(quest) bot_logic.is_started = False messages_list = bot_logic.answer(answer_text) self.assertEqual(bot_logic.is_started, False) quest.assess_answer.assert_not_called() self.assertEqual(messages_list[0].text, bot_logic.messages['bot_not_started']) self.assertEqual(len(messages_list), 1)
def test_send_messages_filled_messages_list(self): quest = MagicMock() update = MagicMock() context = MagicMock() context.bot.send_message.return_value = None msg1 = MagicMock() msg1.text = 'abc' msg1.as_repy = False msg2 = MagicMock() msg2.text = 'def' msg2.as_repy = True messages_list = [msg1, msg2] bot_logic = BotLogic(quest) bot_logic.send_messages(update, context, messages_list) self.assertEqual(context.bot.send_message.call_count, 2)
def setup_robot(): """Setup Robot. Creates an instance of the robot using the configuration from our root `config.ini` file. Returns: An authed instance of our bot. """ # used to grab the config for the bot config = ConfigParser() # should always be on the root folder of this script config.read('./config.ini') # Get the credentials from the config file user = config.get('Credentials', 'user') password = config.get('Credentials', 'password') global npc_id npc_id = config.get('NPC', 'id') coinBrawl = BotLogic(user, password) coinBrawl.auth() # return the robot instance return coinBrawl
def handle_text(message): bot.send_message(message.chat.id, BotLogic().handle_text_message(message.text, message.from_user.id))
def test_init_with_valid_quest(self): quest = MagicMock() bot_logic = BotLogic(quest)
def test_init_with_none_quest(self): quest = None with self.assertRaises(AttributeError): bot_logic = BotLogic(quest)
def main(): settings_provider = BotSettingsProvider() questions_provider = QuestionsProviderPsql(settings_provider) quest = Quest(questions_provider) bot = BotContainer(settings_provider, BotLogic(quest)) bot.start()