Beispiel #1
0
    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()
Beispiel #2
0
    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()
Beispiel #3
0
    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()
Beispiel #4
0
    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()
Beispiel #5
0
    def test_sql_version_matrix(self):
        self.mox.StubOutWithMock(omego.db, 'glob')
        omego.db.glob(
            os.path.join('.', 'sql', 'psql', 'OMERO*', 'OMERO*.sql')
            ).AndReturn(['./sql/psql/OMERO5.0__0/OMERO4.4__0.sql',
                         './sql/psql/OMERO5.1__0/OMERO5.0__0.sql'])
        self.mox.ReplayAll()

        db = self.PartialMockDb(None, None)
        M, versions = db.sql_version_matrix()
        assert versions == ['OMERO4.4__0', 'OMERO5.0__0', 'OMERO5.1__0']
        assert M == [[None, './sql/psql/OMERO5.0__0/OMERO4.4__0.sql', None],
                     [None, None, './sql/psql/OMERO5.1__0/OMERO5.0__0.sql'],
                     [None, None, None]]
        self.mox.VerifyAll()
Beispiel #6
0
    def test_sql_version_matrix(self):
        self.mox.StubOutWithMock(omego.db, 'glob')
        omego.db.glob(os.path.join(
            '.', 'sql', 'psql', 'OMERO*', 'OMERO*.sql')).AndReturn([
                './sql/psql/OMERO5.0__0/OMERO4.4__0.sql',
                './sql/psql/OMERO5.1__0/OMERO5.0__0.sql'
            ])
        self.mox.ReplayAll()

        db = self.PartialMockDb(None, None)
        M, versions = db.sql_version_matrix()
        assert versions == ['OMERO4.4__0', 'OMERO5.0__0', 'OMERO5.1__0']
        assert M == [[None, './sql/psql/OMERO5.0__0/OMERO4.4__0.sql', None],
                     [None, None, './sql/psql/OMERO5.1__0/OMERO5.0__0.sql'],
                     [None, None, None]]
        self.mox.VerifyAll()