class TestDatabase(unittest.TestCase): """ Tests the functionality of the Database for scores, etc. """ def setUp(self): """ Initializes a Database for the filename. """ self.db = Database('database.db') def tearDown(self): """ Does nothing. """ pass def test_insertRow(self): """ Tests that inserting a row into the database works correctly. """ expected_dict = {"games_played": 10, "games_won": 5, "longest_winning_streak": 2, "longest_losing_streak": 3, "current_streak": 1, "shortest_winning_time": 0, "longest_winning_time": 0, "average_winning_time": 0, "fewest_winning_moves": 0, "most_winning_moves": 0, "average_winning_moves": 0, "highest_score": 0, "lowest_score": 0, "average_score": 0} query = "insert into solitaire_test values ('LizTest', 10, 5, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)" self.db.cursor.execute(query) query = "select (games_played, games_won, longest_winning_streak, longest_losing_streak, current_streak) from solitaire_test where username='******'" self.db.cursor.execute(query) results = self.db.fetch_row('LizTest') self.assertEqual(results, expected_dict) def test_fetchRow(self): """ Tests that fetching a row returns a dictionary with keys that include all columns of the database. """ keys = ["username", "games_played", "games_won", "longest_winning_streak", "longest_losing_streak", "current_streak", "shortest_winning_time", "longest_winning_time", "average_winning_time", "fewest_winning_moves", "most_winning_moves", "average_winning_moves", "highest_score", "lowest_score", "total_score"] player_dict = self.db.fetch_row('LizTest') self.assertEqual(player_dict.keys(), keys)
def setUp(self): """ Initializes a Database for the filename. """ self.db = Database('database.db')