def test_smart_reply(self): bot, resources = MockTeleBot(), MockResources() message = MockMessage(id=0x6D6) g_bot = gdgajubot.GDGAjuBot(self.config, bot, resources) text = "I <3 GDG Aracaju" # Mensagens privadas não fazem link message.chat.type = "private" g_bot._smart_reply(message, text) bot.reply_to.assert_called_with(message, text) g_bot._smart_reply(message, text) bot.reply_to.assert_called_with(message, text) # Configurando MockTeleBot.reply_to() para retornar um MockMessage com um message_id bot.reply_to.return_value = MockMessage(message_id=82) # Mensagens de grupo fazem link message.chat.type = "group" g_bot._smart_reply(message, text) bot.reply_to.assert_called_with(message, text) g_bot._smart_reply(message, text) bot.send_message.assert_called_with( message.chat.id, "Clique para ver a última resposta", reply_to_message_id=82)
def test_handle_messages(self): bot, resources = MockTeleBot(), MockResources() g_bot = gdgajubot.GDGAjuBot(bot, resources, self.config) # test simple commands text commands_asserts = { '/events': self._assert_list_upcoming_events, '/start': self._assert_send_welcome, '/changelog': self._assert_changelog, '/book': self._assert_packtpub_free_learning, '/help': self._assert_help_message, } messages = [ MockMessage(id=i, text=cmd, content_type="text") for i, cmd in enumerate(commands_asserts) ] for i, _assert in enumerate(commands_asserts.values()): g_bot.handle_messages(messages[i:i + 1]) _assert(bot, messages[i]) # test qualifying commands text commands_asserts = { '/events@gdgajubot': self._assert_list_upcoming_events, '/start@erickbot': self._assert_send_welcome, '/changelog@wagnerbot': self._assert_changelog, '/book@brandinibot': self._assert_packtpub_free_learning, '/help@thalesbot': self._assert_help_message, } messages = [ MockMessage(id=i, text=cmd, content_type="text") for i, cmd in enumerate(commands_asserts) ] for i, _assert in enumerate(commands_asserts.values()): g_bot.handle_messages(messages[i:i + 1]) _assert(bot, messages[i])
def test_list_upcoming_events(self): bot, resources, message = MockTeleBot(), MockResources(), MockMessage() g_bot = gdgajubot.GDGAjuBot(self.config, bot, resources) g_bot.list_upcoming_events(message) # Verifica se o response criado está correto self._assert_list_upcoming_events(bot, message) # Garante que o cache mutável não gerará uma exceção n_calls = len(bot.method_calls) g_bot.list_upcoming_events(message) self.assertGreater(len(bot.method_calls), n_calls)
def test_packtpub_free_learning(self): bot, resources, message = MockTeleBot(), MockResources(), MockMessage() g_bot = gdgajubot.GDGAjuBot(self.config, bot, resources) ts = resources.book.expires # Sem warning g_bot.packtpub_free_learning(message, now=datetime.fromtimestamp(ts - 10 * 3600, tz=AJU_TZ)) self._assert_packtpub_free_learning(bot, message) # Os próximos testes verificam cada um dos warnings g_bot.packtpub_free_learning(message, now=datetime.fromtimestamp(ts - 59 * 60, tz=AJU_TZ)) self._assert_packtpub_free_learning(bot, message, warning="1 hora") g_bot.packtpub_free_learning(message, now=datetime.fromtimestamp(ts - 29 * 60, tz=AJU_TZ)) self._assert_packtpub_free_learning(bot, message, warning="meia hora") g_bot.packtpub_free_learning(message, now=datetime.fromtimestamp(ts - 9 * 60, tz=AJU_TZ)) self._assert_packtpub_free_learning(bot, message, warning="10 minutos") g_bot.packtpub_free_learning(message, now=datetime.fromtimestamp(ts - 59, tz=AJU_TZ)) self._assert_packtpub_free_learning(bot, message, warning="1 minuto") g_bot.packtpub_free_learning(message, now=datetime.fromtimestamp(ts - 29, tz=AJU_TZ)) self._assert_packtpub_free_learning(bot, message, warning="30 segundos")
def test_about(self): bot, resources, message = MockTeleBot(), MockResources(), MockMessage( id=0xB00B) g_bot = gdgajubot.GDGAjuBot(self.config, bot, resources) g_bot.about(message) self._assert_about(bot, message)
def test_help(self): bot, resources, message = MockTeleBot(), MockResources(), MockMessage() g_bot = gdgajubot.GDGAjuBot(self.config, bot, resources) g_bot.help(message) self._assert_help_message(bot, message)
def test_send_welcome(self): bot, resources, message = MockTeleBot(), MockResources(), MockMessage() g_bot = gdgajubot.GDGAjuBot(self.config, bot, resources) g_bot.send_welcome(message) self._assert_send_welcome(bot, message)
def test_changelog(self): bot, resources, message = MockTeleBot(), MockResources(), MockMessage( id=0xB00B) g_bot = gdgajubot.GDGAjuBot(bot, resources, self.config) g_bot.changelog(message) self._assert_changelog(bot, message)