示例#1
0
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()
示例#2
0
    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)
示例#3
0
    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)