Beispiel #1
0
class TestPost(unittest.TestCase):
    def setUp(self):
        self.database = "test.db"
        self.title = "A TEST TITLE"
        self.author = "A TEST AUTHOR"
        self.post_time = "Fri 11/6/2015 10:38 AM"
        self.url = "http://hehe.com"
        self.seconds = 1446806280
        self.post = Post(self.title, self.author, self.post_time, self.url, database=self.database)

        # 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()

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

    def test_post_time_convert(self):
        self.assertEqual(self.post.post_time, self.seconds)

    def test_post_save(self):
        self.post.save()
        self.conn = sqlite3.connect(self.database)
        self.cursor = self.conn.cursor()
        self.cursor.execute("SELECT * FROM board ORDER BY time DESC LIMIT 1")
        last_item = self.cursor.fetchone()
        self.assertEqual(self.post.title, last_item[0])
        self.assertEqual(self.post.author, last_item[1])
        self.assertEqual(self.post.post_time, last_item[2])
        self.conn.close()
Beispiel #2
0
    def setUp(self):
        self.database = "test.db"
        self.title = "A TEST TITLE"
        self.author = "A TEST AUTHOR"
        self.post_time = "Fri 11/6/2015 10:38 AM"
        self.url = "http://hehe.com"
        self.seconds = 1446806280
        self.post = Post(self.title, self.author, self.post_time, self.url, database=self.database)

        # 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()