def testStepUnauthorized(self): self.setRut() self.retriever.setPath( web_test.TestFilesBasePath().joinpath('pagado_rendido.html')) update = self.simpleCommand('subscribe', cb_reply=self.store_received_string) self.dispatcher.process_update(update) # Process the subscription. self.assertTrue( User(self._db_connection).is_subscribed(self.user1_telegram_id, self.chat_id)) mocked_updater = MagicMock(telegram.ext.Updater) mocked_updater.bot = MagicMock(telegram.Bot) mocked_updater.bot.sendMessage = self.sendMessageMock mocked_query_the_bank = MagicMock( side_effect=telegram.error.Unauthorized('unauthorized')) self.bot.query_the_bank_and_reply = mocked_query_the_bank self.stored = None self.bot.step(mocked_updater) self.assertFalse( User(self._db_connection).is_subscribed(self.user1_telegram_id, self.chat_id)) self.assertEqual(None, self.stored)
def testRutMessage(self): # This enrolls the user. self.retriever.setPath( web_test.TestFilesBasePath().joinpath('pagado_rendido.html')) update = self.simpleMessage(str(self.rut), cb_reply=self.store_received_string) self.dispatcher.process_update(update) self.assertEqual(self._EXPECTED_PAGADO_RENDIDO, self.stored)
def testRutMessageError(self): # This enrolls the user. self.retriever.setPath( web_test.TestFilesBasePath().joinpath('Error.htm')) update = self.simpleMessage(str(self.rut), cb_reply=self.store_received_string) self.dispatcher.process_update(update) self.assertEqual(Messages.INTENTE_NUEVAMENTE_ERROR, self.stored)
def testGetStoredRut(self): expected = self._EXPECTED_PAGADO_RENDIDO self.setRut() self.retriever.setPath( web_test.TestFilesBasePath().joinpath('pagado_rendido.html')) update = self.simpleCommand('get', cb_reply=self.store_received_string) self.dispatcher.process_update(update) self.assertEqual(expected, self.stored)
def testQueryTheBankAndReplyErrorSecondQueryAlways(self): # Inmediate time of expiration for cache. cache = model_interface.Cache(self._db_connection, datetime.timedelta(0)) bot = ValeVistaBot(self._db_connection, self.retriever, cache) # This enrolls the user. self.setRut() self.retriever.setPath( web_test.TestFilesBasePath().joinpath('pagado_rendido.html')) bot.query_the_bank_and_reply(self.user1_telegram_id, self.rut, self.store_received_string, ValeVistaBot.ReplyWhen.ALWAYS) self.assertEqual(self._EXPECTED_PAGADO_RENDIDO, self.stored) self.retriever.setPath( web_test.TestFilesBasePath().joinpath('cliente.html')) bot.query_the_bank_and_reply(self.user1_telegram_id, self.rut, self.store_received_string, ValeVistaBot.ReplyWhen.ALWAYS) self.assertEqual(Messages.CLIENTE_ERROR, self.stored)
def testQueryTheBankAndReply(self): self.stored = None # This enrolls the user. self.setRut() self.retriever.setPath( web_test.TestFilesBasePath().joinpath('pagado_rendido.html')) self.bot.query_the_bank_and_reply( self.user1_telegram_id, self.rut, self.store_received_string, ValeVistaBot.ReplyWhen.IS_USEFUL_FOR_USER) self.assertIsNone(self.stored)
def testSimpleQueryTheBankAndReply(self): expected = self._EXPECTED_PAGADO_RENDIDO # This enrolls the user. self.setRut() self.retriever.setPath( web_test.TestFilesBasePath().joinpath('pagado_rendido.html')) self.bot.query_the_bank_and_reply(self.user1_telegram_id, self.rut, self.store_received_string, ValeVistaBot.ReplyWhen.ALWAYS) self.assertEqual(expected, self.stored)
def testQueryTheBankAndReplyTwoErrorSecondQueryIfUseful(self): # Inmediate time of expiration for cache. cache = model_interface.Cache(self._db_connection, datetime.timedelta(0)) bot = ValeVistaBot(self._db_connection, self.retriever, cache) # This enrolls the user. self.setRut() self.retriever.setPath( web_test.TestFilesBasePath().joinpath('cliente.html')) bot.query_the_bank_and_reply(self.user1_telegram_id, self.rut, self.store_received_string, ValeVistaBot.ReplyWhen.ALWAYS) self.assertEqual(Messages.CLIENTE_ERROR, self.stored) self.retriever.setPath( web_test.TestFilesBasePath().joinpath('Error.htm')) self.stored = None bot.query_the_bank_and_reply(self.user1_telegram_id, self.rut, self.store_received_string, ValeVistaBot.ReplyWhen.IS_USEFUL_FOR_USER) self.assertEqual(None, self.stored)
def testQueryTheBankAndReplyUseful(self): expected = self._EXPECTED_PAGADO_RENDICION self.stored = None # This enrolls the user. self.setRut() self.retriever.setPath( web_test.TestFilesBasePath().joinpath('pagado_rendicion.html')) self.bot.query_the_bank_and_reply( self.user1_telegram_id, self.rut, self.store_received_string, ValeVistaBot.ReplyWhen.IS_USEFUL_FOR_USER) self.assertEqual(expected, self.stored)
def testGetStoredRutOnEmpty(self): self.setRut() self.retriever.setPath( web_test.TestFilesBasePath().joinpath('no_pagos.html')) update = self.simpleCommand('get', cb_reply=self.store_received_string) self.dispatcher.process_update(update) self.assertEqual(Messages.NO_PAGOS, self.stored) # Check when loading from cache. update = self.simpleCommand('get', cb_reply=self.store_received_string) self.dispatcher.process_update(update) self.assertEqual(Messages.NO_PAGOS, self.stored)
def testPreStep(self): self.setRut() self.retriever.setPath( web_test.TestFilesBasePath().joinpath('pagado_rendido.html')) update = self.simpleCommand('subscribe', cb_reply=self.store_received_string) self.dispatcher.process_update(update) # Process the subscription. update = self.simpleCommand('get', cb_reply=self.store_received_string) # Process the get to populate the cache. self.dispatcher.process_update(update) self.stored = None self.assertFalse( User(self._db_connection).get_subscribers_to_update(1)) subscribers = User(self._db_connection).get_subscribers_to_update(0) self.assertEqual(1, len(subscribers))
def testStepNoUpdate(self): self.setRut() self.retriever.setPath( web_test.TestFilesBasePath().joinpath('pagado_rendido.html')) update = self.simpleCommand('subscribe', cb_reply=self.store_received_string) self.dispatcher.process_update(update) # Process the subscription. mocked_updater = MagicMock(telegram.ext.Updater) mocked_updater.bot = MagicMock(telegram.Bot) mocked_updater.bot.sendMessage = self.sendMessageMock self.stored = None self.bot.step(mocked_updater) self.assertIsNone(self.stored) self.stored = None self.bot.step(mocked_updater) self.assertEqual(None, self.stored)