def test_init(self, sqlfile, dryrun): ext = self.mox.CreateMock(External) if sqlfile != 'notprovided': omerosql = 'omero.sql' else: omerosql = None args = self.Args({ 'omerosql': omerosql, 'rootpass': '******', 'dry_run': dryrun }) db = self.PartialMockDb(args, ext) self.mox.StubOutWithMock(db, 'psql') self.mox.StubOutWithMock(omego.fileutils, 'timestamp_filename') self.mox.StubOutWithMock(os.path, 'exists') self.mox.StubOutWithMock(db, 'upgrade') if sqlfile == 'notprovided': omerosql = 'omero-00000000-000000-000000.sql' omego.fileutils.timestamp_filename('omero', 'sql').AndReturn(omerosql) else: os.path.exists(omerosql).AndReturn(sqlfile == 'exists') if sqlfile == 'notprovided' and not dryrun: ext.omero_cli( ['db', 'script', '-f', omerosql, '', '', args.rootpass]) if sqlfile == 'exists': db.upgrade() if sqlfile != 'missing' and not dryrun: db.psql('-f', omerosql) self.mox.ReplayAll() if sqlfile == 'missing': with pytest.raises(Stop) as excinfo: db.init() assert str(excinfo.value) == 'SQL file not found' else: db.init() self.mox.VerifyAll()
def test_init(self, sqlfile, dryrun): ext = self.mox.CreateMock(External) if sqlfile != 'notprovided': omerosql = 'omero.sql' else: omerosql = None args = self.Args({'omerosql': omerosql, 'rootpass': '******', 'dry_run': dryrun}) db = self.PartialMockDb(args, ext) self.mox.StubOutWithMock(db, 'psql') self.mox.StubOutWithMock(omego.fileutils, 'timestamp_filename') self.mox.StubOutWithMock(os.path, 'exists') self.mox.StubOutWithMock(db, 'upgrade') if sqlfile == 'notprovided': omerosql = 'omero-00000000-000000-000000.sql' omego.fileutils.timestamp_filename('omero', 'sql').AndReturn( omerosql) else: os.path.exists(omerosql).AndReturn(sqlfile == 'exists') if sqlfile == 'notprovided' and not dryrun: ext.omero_cli([ 'db', 'script', '-f', omerosql, '', '', args.rootpass]) if sqlfile == 'exists': db.upgrade() if sqlfile != 'missing' and not dryrun: db.psql('-f', omerosql) self.mox.ReplayAll() if sqlfile == 'missing': with pytest.raises(Stop) as excinfo: db.init() assert str(excinfo.value) == 'SQL file not found' else: db.init() self.mox.VerifyAll()