Exemple #1
0
class TestBoardBot(unittest.TestCase):
    def setUp(self):
        self.database = "test.db"
        # Init database
        self.conn = sqlite3.connect(self.database)
        self.cursor = self.conn.cursor()
        self.cursor.execute("CREATE TABLE board (title TEXT, author TEXT, time INT, url TEXT)")
        self.conn.commit()
        self.conn.close()

        self.bot = BoardBot(self.database)

    def tearDown(self):
        self.conn.close()
        os.remove(self.database)

    def test_retrieve_posts(self):
        self.bot.retrieve_posts()
        self.assertEqual(25, len(self.bot.posts))

    def test_save_posts(self):
        self.bot.save_posts()
        self.conn = sqlite3.connect(self.database)
        self.cursor = self.conn.cursor()
        self.cursor.execute("SELECT * FROM board")
        self.assertEqual(25, len(self.cursor.fetchall()))
Exemple #2
0
def main():
    tBot = telepot.Bot(settings.BOT_TOKEN)
    tBot.sendMessage(settings.CHAT_ID, 
            '<NoticeBoardRSS>: Start fetching new posts')
    try:
        bot = BoardBot(settings.DATABASE)
        count = bot.save_posts()
        tBot.sendMessage(settings.CHAT_ID,
                '<NoticeBoardRSS>: Successfully fetched {} new posts'.format(
                    count))
    except Exception, e:
        tBot.sendMessage(settings.CHAT_ID,
                '<NoticeBoardRSS>: Job Failed! Error message:\n' + str(e))
Exemple #3
0
    def setUp(self):
        self.database = "test.db"
        # Init database
        self.conn = sqlite3.connect(self.database)
        self.cursor = self.conn.cursor()
        self.cursor.execute("CREATE TABLE board (title TEXT, author TEXT, time INT, url TEXT)")
        self.conn.commit()
        self.conn.close()

        self.bot = BoardBot(self.database)