Return game list as dict

This commit is contained in:
Mathieu Comandon 2013-03-20 22:34:30 +01:00
parent 96b5d9d8f4
commit e234c7a60e
2 changed files with 18 additions and 5 deletions

View file

@ -42,7 +42,6 @@ def create():
slug TEXT,
machine TEXT,
runner TEXT,
icon TEXT,
executable TEXT,
directory TEXT,
lastplayed INTEGER)"""
@ -64,10 +63,15 @@ def get_games(name_filter=None):
rows = cur.execute(query)
results = rows.fetchall()
column_names = [column[0] for column in cur.description]
print column_names
cur.close()
con.close()
return results
game_list = []
for row in results:
game_info = {}
for index, column in enumerate(column_names):
game_info[column] = row[index]
game_list.append(game_info)
return game_list
def add_game(name, machine, runner):

View file

@ -10,18 +10,27 @@ class TestPersonnalGameArchive(unittest.TestCase):
def setUp(self):
pga.PGA_DB = TEST_PGA_PATH
pga.create()
pga.add_game(name="LutrisTest", machine="Linux", runner="Linux")
def tearDown(self):
os.remove(TEST_PGA_PATH)
def test_add_game(self):
pga.add_game(name="LutrisTest", machine="Linux", runner="Linux")
game_list = pga.get_games()
game_names = [item[1] for item in game_list]
game_names = [item['name'] for item in game_list]
self.assertTrue("LutrisTest" in game_names)
def test_delete_game(self):
pga.delete_game("LutrisTest")
game_list = pga.get_games()
self.assertEqual(len(game_list), 0)
pga.add_game(name="LutrisTest", machine="Linux", runner="Linux")
def test_get_game_list(self):
game_list = pga.get_games()
self.assertEqual(game_list[0]['slug'], 'lutristest')
self.assertEqual(game_list[0]['name'], 'LutrisTest')
self.assertEqual(game_list[0]['runner'], 'Linux')
if __name__ == '__main__':
unittest.main()