def testMigrate(self): self.cfg = config.UpsrvConfig() self.cfg.downloadDB = "sqlite:///%s/%s" % (self.workDir, "upsrv.sqlite") self.wcfg = app.configure(self.cfg) maker = self.wcfg.registry.settings['db.sessionmaker'] # New maker, without extensions, we don't need transaction # management makerArgs = maker.kw.copy() del makerArgs['extension'] maker = maker.__class__(**makerArgs) conn = maker() conn.execute(""" CREATE TABLE databaseversion ( version integer NOT NULL, minor integer NOT NULL, PRIMARY KEY ( version, minor ) )""") conn.execute(""" INSERT INTO databaseversion (version, minor) VALUES (0, 1) """) db.schema.updateSchema(conn) conn.commit() versions = [ x for x in conn.execute("select version, minor from databaseversion") ] self.assertEquals(versions, [ db.migrate.Version ]) conn.close()
def setUp(self): testcase.TestCaseWithWorkDir.setUp(self) # Delete all root handlers for handler in logging.root.handlers: logging.root.removeHandler(handler) logging.basicConfig(level=logging.DEBUG) self.logHandler = logging.root.handlers[0] mock.mockMethod(self.logHandler.handle) self.cfg = config.UpsrvConfig() self.cfg.downloadDB = "sqlite:///%s/%s" % (self.workDir, "upsrv.sqlite") salt = file("/dev/urandom").read(8).encode('hex') self.cfg.configLine('password %s %s' % ( self.Username, crypt.crypt(self.Password, '$1$%s$' % salt))) self.wcfg = app.configure(self.cfg) maker = self.wcfg.registry.settings['db.sessionmaker'] # New maker, without extensions, we don't need transaction # management makerArgs = maker.kw.copy() del makerArgs['extension'] maker = maker.__class__(**makerArgs) conn = maker() db.schema.updateSchema(conn) conn.commit() self.conn = conn self.app = self.wcfg.make_wsgi_app() # Mock the conary config object self.conaryCfg = conarycfg.ConaryConfiguration(False) self.conaryCfg.root = "%s/%s" % (self.workDir, "__root__") mock.mock(conarycfg, 'ConaryConfiguration', self.conaryCfg)