def test_upgrade(self, needupdate): args = self.Args({'dry_run': False}) db = self.PartialMockDb(args, None) self.mox.StubOutWithMock(db, 'get_current_db_version') self.mox.StubOutWithMock(db, 'sql_version_matrix') self.mox.StubOutWithMock(db, 'sql_version_resolve') self.mox.StubOutWithMock(db, 'psql') versions = ['OMERO3.0__0', 'OMERO4.4__0', 'OMERO5.0__0'] if needupdate: db.get_current_db_version().AndReturn(('OMERO3.0', '0')) db.sql_version_matrix().AndReturn(([], versions)) db.sql_version_resolve([], versions, versions[0]).AndReturn([ './sql/psql/OMERO4.4__0/OMERO3.0__0.sql', './sql/psql/OMERO5.0__0/OMERO4.4__0.sql' ]) db.psql('-f', './sql/psql/OMERO4.4__0/OMERO3.0__0.sql') db.psql('-f', './sql/psql/OMERO5.0__0/OMERO4.4__0.sql') else: db.get_current_db_version().AndReturn(('OMERO5.0', '0')) db.sql_version_matrix().AndReturn(([], versions)) self.mox.ReplayAll() db.upgrade() self.mox.VerifyAll()
def test_upgrade_dryrun(self, needupdate): args = self.Args({'dry_run': True}) db = self.PartialMockDb(args, None) self.mox.StubOutWithMock(db, 'get_current_db_version') self.mox.StubOutWithMock(db, 'sql_version_matrix') self.mox.StubOutWithMock(db, 'sql_version_resolve') # Stub out to ensure it's NOT called self.mox.StubOutWithMock(db, 'psql') versions = ['OMERO4.4__0', 'OMERO5.0__0'] if needupdate: db.get_current_db_version().AndReturn(('OMERO4.4', '0')) db.sql_version_matrix().AndReturn(([], versions)) db.sql_version_resolve([], versions, versions[0]).AndReturn( ['./sql/psql/OMERO5.0__0/OMERO4.4__0.sql']) else: db.get_current_db_version().AndReturn(('OMERO5.0', '0')) db.sql_version_matrix().AndReturn(([], versions)) self.mox.ReplayAll() if needupdate: with pytest.raises(Stop) as excinfo: db.upgrade() assert excinfo.value.rc == 2 assert excinfo.value.message == ( 'Database upgrade required OMERO4.4__0->OMERO5.0__0') else: db.upgrade() self.mox.VerifyAll()
def test_upgrade(self, needupdate): args = self.Args({'dry_run': False}) db = self.PartialMockDb(args, None) self.mox.StubOutWithMock(db, 'get_current_db_version') self.mox.StubOutWithMock(db, 'sql_version_matrix') self.mox.StubOutWithMock(db, 'sql_version_resolve') self.mox.StubOutWithMock(db, 'psql') versions = ['OMERO3.0__0', 'OMERO4.4__0', 'OMERO5.0__0'] if needupdate: db.get_current_db_version().AndReturn(('OMERO3.0', '0')) db.sql_version_matrix().AndReturn(([], versions)) db.sql_version_resolve([], versions, versions[0]).AndReturn( ['./sql/psql/OMERO4.4__0/OMERO3.0__0.sql', './sql/psql/OMERO5.0__0/OMERO4.4__0.sql']) db.psql('-f', './sql/psql/OMERO4.4__0/OMERO3.0__0.sql') db.psql('-f', './sql/psql/OMERO5.0__0/OMERO4.4__0.sql') else: db.get_current_db_version().AndReturn(('OMERO5.0', '0')) db.sql_version_matrix().AndReturn(([], versions)) self.mox.ReplayAll() db.upgrade() self.mox.VerifyAll()
def test_upgrade_not_initialised(self, dryrun): args = self.Args({'dry_run': dryrun}) db = self.PartialMockDb(args, None) self.mox.StubOutWithMock(db, 'get_current_db_version') exc = RunException('test psql failure', 'psql', [], -1, '', '') db.get_current_db_version().AndRaise(exc) self.mox.ReplayAll() with pytest.raises(Stop) as excinfo: db.upgrade() assert excinfo.value.rc == 3 assert excinfo.value.message == 'Unable to get database version' 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()
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()