Beispiel #1
0
 def test_telegram_bot_custom_config(self):
     section = 'my.section'
     key = 'my_token'
     val = 'my_value'
     TestTokenProviderWithConfigFile.create_config('my.section', 'my_token', val)
     token_provider = TokenProvider(TestTokenProviderWithConfigFile.real_config_file_name, telegram_bot_section=section, telegram_bot_token_key=key)
     token = token_provider.get_token()
     self.assertEqual(token, val)
Beispiel #2
0
import time

from dooralert import TokenProvider, DoorAlertBot, BotMessageHandler

if __name__ == '__main__':
    config_file_name = 'dooralertbot.ini'
    telegram_bot_section = 'telegram.bot'
    telegram_bot_token_key = 'token'

    bot_message_handler = BotMessageHandler()
    config_provider = TokenProvider(
        config_file_name=config_file_name,
        telegram_bot_section=telegram_bot_section,
        telegram_bot_token_key=telegram_bot_token_key)
    bot = DoorAlertBot(config_provider=config_provider,
                       telegram_bot_message_handler=bot_message_handler)

    bot.init_bot()
    bot.init_handlers()
    bot.polling(none_stop=True)
Beispiel #3
0
 def test_telegram_bot_default_config(self):
     token_provider = TokenProvider(TestTokenProviderWithConfigFile.real_config_file_name)
     token = token_provider.get_token()
     self.assertEqual(token, TestTokenProviderWithConfigFile.telegram_bot_token_value)
Beispiel #4
0
 def test_telegram_bot_token_key_is_none(self):
     token_provider = TokenProvider(TestTokenProviderWithConfigFile.real_config_file_name, telegram_bot_token_key=None)
     with self.assertRaises(KeyError) as cm:
         token_provider.get_token()
Beispiel #5
0
 def test_config_file_does_not_exist(self):
     with self.assertRaises(FileNotFoundError) as cm:
         TokenProvider('unknown.txt')
Beispiel #6
0
 def test_config_file_name_is_none(self):
     with self.assertRaises(ValueError) as cm:
         TokenProvider(config_file_name=None)
     self.assertEqual(str(cm.exception), 'Config file name is none.')