class TestFileHandler(unittest.TestCase):
    def setUp(self):
        self.fh = FileHandler("..")

    def test_save_and_load_json(self):
        sample_json = {}
        sample_json["testbool"] = True
        sample_json["teststring"] = "hello world"

        self.fh.save_json(sample_json, "resources/sample.json")
        data = self.fh.load_json("resources/sample.json")
        self.assertEqual(data["testbool"], True)
        self.assertEqual(data["teststring"], "hello world")

    def test_save_and_load_file(self):
        data = "text message"
        self.fh.save_file(data=data, path="resources/sample.txt")
        result = self.fh.load_file("resources/sample.txt")
        self.assertEqual(result, "text message")

    def test_file_exists(self):
        data = "text message"
        self.fh.save_file(data=data, path="resources/sample.txt")
        self.assertTrue(self.fh.file_exists("resources/sample.txt"))

    def tearDown(self):
        base_path = os.path.abspath(os.path.dirname(__file__))
        filepath_json = os.path.join(base_path, '..', "resources/sample.json")
        filepath_text = os.path.join(base_path, '..', "resources/sample.txt")
        if os.path.exists(filepath_json):
            os.remove(filepath_json)
        if os.path.exists(filepath_text):
            os.remove(filepath_text)
Exemplo n.º 2
0
    def help(self, bot, update):
        """
        Send a message when the command /help is issued.
        """

        message = "If you need help with handling the commands, please have a look at my <a href='https://github.com/serguk89/telegram-rss'>Github</a> page. There I have summarized everything necessary for you!"
        update.message.reply_text(message, parse_mode=ParseMode.HTML)

    def stop(self, bot, update):
        """
        Stops the bot from working
        """

        telegram_user = update.message.from_user
        self.db.update_user(telegram_id=telegram_user.id, is_active=0)

        message = "Oh.. Okay, I will not send you any more news updates! If you change your mind and you want to receive messages from me again use /start command again!"
        update.message.reply_text(message)


if __name__ == '__main__':
    # Load Credentials
    fh = FileHandler("..")
    credentials = fh.load_json("resources/credentials.json")

    # Pass Credentials to bot
    token = credentials["telegram_token"]
    update = credentials["update_interval"]
    RobotRss(telegram_token=token, update_interval=update)