Example #1
0
 def test_from_string(self):
   self.assertIsInstance(
     sms_sender.get(self.config, 'MB'), sms_sender.MBSender)
   self.assertIsInstance(
     sms_sender.get(self.config, 'NX'), sms_sender.NXSender)
   self.assertIsInstance(
     sms_sender.get(self.config, 'nx'), sms_sender.NXSender)
   self.assertIsInstance(
     sms_sender.get(self.config, 'Fake'), sms_sender.FakeSender)
   self.assertIsInstance(
     sms_sender.get(self.config, 'fake'), sms_sender.FakeSender)
Example #2
0
def main(argv):
  cfg = config.Config(FLAGS.config, mode=FLAGS.mode, env_path=FLAGS.dotenv_path)
  if FLAGS.phone is not None:
    for sms_carrier in ['TW', 'NX', 'MB']:
      ms = sms_sender.get(cfg, sms_carrier=sms_carrier)
      ms.send(FLAGS.phone, f"Test from  {sms_carrier}")
  else:
    logging.error('Specify a phone number.')
Example #3
0
 def __init__(self, config, port=8889):
     super().__init__(config, port)
     self.port = port if port is not None else self.config.messaging.port
     self.sender = sms_sender.get(self.config)
     self.queue = queues.Queue()
     self.scheduler = scheduler.MessageScheduler(
         config=self.config, db=self.db_factory.create(), queue=self.queue)
     self.callbacks = [self.process]
Example #4
0
 def __init__(self, config, port=8889):
   super().__init__(config, port)
   self.port = port if port is not None else self.config.messaging.port
   self.sender = sms_sender.get(self.config)
   self.queue = queues.Queue()
   self.scheduler = scheduler.MessageScheduler(
     config=self.config, db=self.db, queue=self.queue)
   print([m.text for m in self.scheduler.messages])
   self.callbacks = [self.process]
Example #5
0
 def test_from_string(self):
     self.assertIsInstance(sms_sender.get(self.config, 'MB'),
                           sms_sender.MBSender)
     self.assertIsInstance(sms_sender.get(self.config, 'NX'),
                           sms_sender.NXSender)
     self.assertIsInstance(sms_sender.get(self.config, 'nx'),
                           sms_sender.NXSender)
     self.assertIsInstance(sms_sender.get(self.config, 'Fake'),
                           sms_sender.FakeSender)
     self.assertIsInstance(sms_sender.get(self.config, 'fake'),
                           sms_sender.FakeSender)
     with self.assertRaisesRegex(ValueError, 'Incorrect sms carrier'):
         sms_sender.get(self.config, 'dummy_sms_sender_name')
Example #6
0
File: sender.py Project: rth/icubam
    def __init__(self, config, db, queue, tg_bot=None):
        self.config = config
        self.db = db
        self.queue = queue
        self.formatter = message_formatter.MessageFormatter()

        try:
            self.sms_sender = sms_sender.get(config)
        except Exception as e:
            logging.warning(f"Cannot set sms_sender {e}")
            self.sms_sender = None

        try:
            self.email_sender = email_sender.get(config)
        except Exception as e:
            logging.warning(f"Cannot set email_sender {e}")
            self.email_sender = None

        # This might return be None if telegram is not properly set.
        self.telegram_bot = integrator.TelegramSetup(config, db,
                                                     tg_bot=tg_bot).bot
Example #7
0
 def test_send_from_fake_sender(self):
     ms = sms_sender.get(self.config, 'Fake')
     # send message with Fake sender is safe.
     # It only prints to standard output the message
     ms.send("Fake phone number", "Hello from tests")
Example #8
0
 def test_from_config(self):
     self.assertIsInstance(sms_sender.get(self.config),
                           sms_sender.FakeSender)