def _createFlavors(db): if "Flavors" in db.tables: return cu = db.cursor() idtable.createIdTable(db, "Flavors", "flavorId", "flavor") cu.execute("SELECT FlavorID from Flavors") if cu.fetchone() == None: # reserve flavor 0 for "no flavor information" cu.execute("INSERT INTO Flavors VALUES (0, NULL)") idtable.createMappingTable(db, "DBFlavorMap", "instanceId", "flavorId") db.commit() db.loadSchema()
def testIdMapping(self): cx = self.getDB() idtable.createMappingTable(cx, 'test', 'thekey', 'val') tbl = idtable.IdMapping(cx, "test", "thekey", "val") tbl[2] = 5 tbl[5] = 10 assert (tbl[2] == 5) assert (tbl[5] == 10) del (tbl[2]) self.assertRaises(KeyError, tbl.__getitem__, 2) assert (tbl.get(2, 3.14159) == 3.14159)
def testIdMapping(self): cx = self.getDB() idtable.createMappingTable(cx, 'test', 'thekey', 'val') tbl = idtable.IdMapping(cx, "test", "thekey", "val") tbl[2] = 5 tbl[5] = 10 assert(tbl[2] == 5) assert(tbl[5] == 10) del(tbl[2]) self.assertRaises(KeyError, tbl.__getitem__, 2) assert(tbl.get(2, 3.14159) == 3.14159)