Ejemplo n.º 1
0
class Test_ConfigHandler(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)
        self.m_cnfgHdl = []
        if not os.path.exists('./tmp'):
            os.makedirs('./tmp')
        if os.path.exists('./tmp/config.txt'):
            os.remove('./tmp/config.txt')
        with open('./tmp/config.txt', 'w') as f:
            f.write('[DoorConfig]\nInvertInput = True\nDummyProperty=7')

    def setUp(self):
        self.m_cnfgHdl = ConfigHandler('tmp/config.txt')

    def tearDown(self):
        pass

    def test_Option_InvertInput(self):
        option = self.m_cnfgHdl.getOption('InvertInput')
        self.assertEqual('True', option)

    def test_Option_InvertInputBool(self):
        option = self.m_cnfgHdl.getOptionBool('InvertInput')
        self.assertEqual(True, option)

    def test_missingFile(self):
        cnfgHdl = ConfigHandler('tmp/config_not_exist.txt')
        self.assertEqual(False, cnfgHdl.optionFileFound())

    def test_existingFile(self):
        cnfgHdl = ConfigHandler('tmp/config.txt')
        self.assertEqual(True, cnfgHdl.optionFileFound())
    m_userAccessList = UserListHandler(m_debugLogger)
    m_userAccessList.initialize('./cnfg/registeredIds.txt')
    m_userAccessList.loadList()
    #m_userAccessList.printList()

    m_userNotificationList = UserListHandler(m_debugLogger)
    m_userNotificationList.initialize('./cnfg/notificationIds.txt')
    m_userNotificationList.loadList()
    #m_userNotificationList.printList()

    m_accessRequestHandler = AccesRequestHandler()
    m_accessRequestHandler.initialize()

    # Use GPIO 23
    m_doorStateInput = BooleanSignalInput(
        m_cnfgHdl.getOptionBool('InvertInput'))
    m_doorStateInput.initialize(23)

    # Use GPIO 24
    m_doorMovementOutput = OutputPulseHandler()
    m_doorMovementOutput.initialize(24, False)

    if '' == m_telegramId:
        m_debugLogger.logText(
            'Internal telegram id not found. Create a file "cnfg/botId.txt" containing the ID of the bot.'
        )
    else:
        bot = telepot.Bot(m_telegramId)
        m_doorStats = DoorStatistics(bot, m_debugLogger)
        bot.message_loop(handle)