class TestDBWriter(unittest.TestCase): def setUp(self): self.db = DBWriter() self.db.reader = MockRedditReader('news') self.db.table = "test_headlines" def tearDown(self): self.db.drop_table() def test_create_table(self): self.assertFalse(self.db._exists()) self.db.create_table() self.assertTrue(self.db._exists()) def test__article_data(self): self.db.create_table() self.assertIsNone(self.db._article_data({"id": "not_an_id"})) def test_update(self): data_size = len(list(self.db.reader.gen_articles())) self.db.create_table() self.assertEqual(self.db._count(), 0, "No rows should have been added yet") self.db.update() self.assertEqual(self.db._count(), data_size, "The table should have been updated") self.db.update() self.assertEqual( self.db._count(), data_size, "Second update shouldn't change anything (count is {:,d} instead of {:d})".format( self.db._count(), data_size))
def setUp(self): self.db = DBWriter() self.db.reader = MockRedditReader('news') self.db.table = "test_headlines"
def test_fetch_raw_data(): db = DBWriter() assert_equal(db._count(), len(fetch_raw_data()))