예제 #1
0
파일: test_db.py 프로젝트: ome/omego
    def test_pgdump(self):
        db = self.PartialMockDb(None, None)
        self.mox.StubOutWithMock(db, 'get_db_args_env')
        self.mox.StubOutWithMock(External, 'run')

        pgdumpargs = ['-d', 'name', '-h', 'host', '-U', 'user',
                      '-w', 'arg1', 'arg2']
        db.get_db_args_env().AndReturn(self.create_db_test_params())
        External.run('pg_dump', pgdumpargs, capturestd=True,
                     env={'PGPASSWORD': '******'}).AndReturn(('', ''))
        self.mox.ReplayAll()

        db.pgdump('arg1', 'arg2')
        self.mox.VerifyAll()
예제 #2
0
    def test_get_db_args_env(self, dbname, hasconfig, noconfig):
        ext = self.mox.CreateMock(External)
        args = self.Args({
            'dbhost': 'host',
            'dbname': dbname,
            'dbuser': '******',
            'dbpass': '******',
            'no_db_config': noconfig
        })
        db = self.PartialMockDb(args, ext)
        self.mox.StubOutWithMock(db.external, 'has_config')
        self.mox.StubOutWithMock(db.external, 'get_config')
        self.mox.StubOutWithMock(os.environ, 'copy')

        if noconfig or not hasconfig:
            expecteddb, expectedenv = self.create_db_test_params()
        else:
            expecteddb, expectedenv = self.create_db_test_params('ext')

        if not noconfig:
            cfg = {}
            if hasconfig:
                cfg = {
                    'omero.db.host': 'exthost',
                    'omero.db.user': '******',
                    'omero.db.pass': '******',
                }
                if dbname:
                    cfg['omero.db.name'] = 'extname'

                db.external.get_config(force=True).AndReturn(cfg)
            else:
                db.external.get_config().AndRaise(Exception())

        os.environ.copy().AndReturn({'PGPASSWORD': '******'})

        self.mox.ReplayAll()
        if dbname:
            rcfg, renv = db.get_db_args_env()
            assert rcfg == expecteddb
            assert renv == expectedenv
        else:
            with pytest.raises(Exception) as excinfo:
                db.get_db_args_env()
            assert str(excinfo.value) == 'Database name required'
예제 #3
0
    def test_pgdump(self):
        db = self.PartialMockDb(None, None)
        self.mox.StubOutWithMock(db, 'get_db_args_env')
        self.mox.StubOutWithMock(External, 'run')

        pgdumpargs = [
            '-d', 'name', '-h', 'host', '-U', 'user', '-w', 'arg1', 'arg2'
        ]
        db.get_db_args_env().AndReturn(self.create_db_test_params())
        External.run('pg_dump',
                     pgdumpargs,
                     capturestd=True,
                     env={
                         'PGPASSWORD': '******'
                     }).AndReturn(('', ''))
        self.mox.ReplayAll()

        db.pgdump('arg1', 'arg2')
        self.mox.VerifyAll()
예제 #4
0
파일: test_db.py 프로젝트: ome/omego
    def test_get_db_args_env(self, dbname, hasconfig, noconfig):
        ext = self.mox.CreateMock(External)
        args = self.Args({'dbhost': 'host', 'dbname': dbname,
                          'dbuser': '******', 'dbpass': '******',
                          'no_db_config': noconfig})
        db = self.PartialMockDb(args, ext)
        self.mox.StubOutWithMock(db.external, 'has_config')
        self.mox.StubOutWithMock(db.external, 'get_config')
        self.mox.StubOutWithMock(os.environ, 'copy')

        if noconfig or not hasconfig:
            expecteddb, expectedenv = self.create_db_test_params()
        else:
            expecteddb, expectedenv = self.create_db_test_params('ext')

        if not noconfig:
            cfg = {}
            if hasconfig:
                cfg = {
                    'omero.db.host': 'exthost',
                    'omero.db.user': '******',
                    'omero.db.pass': '******',
                }
                if dbname:
                    cfg['omero.db.name'] = 'extname'

                db.external.get_config(force=True).AndReturn(cfg)
            else:
                db.external.get_config().AndRaise(Exception())

        os.environ.copy().AndReturn({'PGPASSWORD': '******'})

        self.mox.ReplayAll()
        if dbname:
            rcfg, renv = db.get_db_args_env()
            assert rcfg == expecteddb
            assert renv == expectedenv
        else:
            with pytest.raises(Exception) as excinfo:
                db.get_db_args_env()
            assert str(excinfo.value) == 'Database name required'
예제 #5
0
    def test_dump(self, dumpfile, dryrun):
        args = self.Args({'dry_run': dryrun, 'dumpfile': dumpfile})
        db = self.PartialMockDb(args, None)
        self.mox.StubOutWithMock(omego.fileutils, 'timestamp_filename')
        self.mox.StubOutWithMock(db, 'get_db_args_env')
        self.mox.StubOutWithMock(db, 'pgdump')

        if not dumpfile:
            db.get_db_args_env().AndReturn(self.create_db_test_params())

            dumpfile = 'omero-database-name-00000000-000000-000000.pgdump'
            omego.fileutils.timestamp_filename('omero-database-name',
                                               'pgdump').AndReturn(dumpfile)

        if not dryrun:
            db.pgdump('-Fc', '-f', dumpfile).AndReturn('')

        self.mox.ReplayAll()

        db.dump()
        self.mox.VerifyAll()
예제 #6
0
파일: test_db.py 프로젝트: ome/omego
    def test_dump(self, dumpfile, dryrun):
        args = self.Args({'dry_run': dryrun, 'dumpfile': dumpfile})
        db = self.PartialMockDb(args, None)
        self.mox.StubOutWithMock(omego.fileutils, 'timestamp_filename')
        self.mox.StubOutWithMock(db, 'get_db_args_env')
        self.mox.StubOutWithMock(db, 'pgdump')

        if not dumpfile:
            db.get_db_args_env().AndReturn(self.create_db_test_params())

            dumpfile = 'omero-database-name-00000000-000000-000000.pgdump'
            omego.fileutils.timestamp_filename(
                'omero-database-name', 'pgdump').AndReturn(dumpfile)

        if not dryrun:
            db.pgdump('-Fc', '-f', dumpfile).AndReturn('')

        self.mox.ReplayAll()

        db.dump()
        self.mox.VerifyAll()