Beispiel #1
0
    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)
Beispiel #2
0
 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)
Beispiel #3
0
 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)
Beispiel #4
0
 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)
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 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)
Beispiel #10
0
 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)
Beispiel #11
0
    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))
Beispiel #12
0
    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)