def test_startDatabaseRunning(self): """ Ensure that if we can connect to postgres we don't spawn pg_ctl """ self.cursorHistory = [] class DummyCursor(object): def __init__(self, historyHolder): self.historyHolder = historyHolder def execute(self, *args): self.historyHolder.cursorHistory.append(args) def close(self): pass class DummyConnection(object): def __init__(self, historyHolder): self.historyHolder = historyHolder def cursor(self): return DummyCursor(self.historyHolder) def commit(self): pass def close(self): pass def produceConnection(*args): return DummyConnection(self) dummyReactor = DummyProcessReactor() svc = PostgresService( FilePath("postgres_4.pgdb"), lambda x : Service(), "", reactor=dummyReactor, ) svc.produceConnection = produceConnection svc.env = {} svc.startDatabase() self.assertEquals( self.cursorHistory, [ ('commit',), ("create database subpostgres with encoding 'UTF8'",), ('',) ] ) self.assertEquals(dummyReactor.spawnedProcesses, [])
def test_startDatabaseNotRunning(self): """ Ensure that if we can't connect to postgres we spawn pg_ctl """ def produceConnection(*args): raise pgdb.DatabaseError dummyReactor = DummyProcessReactor() svc = PostgresService( FilePath("postgres_4.pgdb"), lambda x : Service(), "", reactor=dummyReactor, ) svc.produceConnection = produceConnection svc.env = {} svc.startDatabase() self.assertEquals(len(dummyReactor.spawnedProcesses), 1) self.assertTrue(dummyReactor.spawnedProcesses[0]._executable.endswith("pg_ctl"))