コード例 #1
0
def parametrized_setup(request, tmpdir):
    from postgraas_server.management_resources import db
    cfg = tmpdir.join('config')
    with open(cfg.strpath, "w") as fp:
        json.dump(CONFIGS[request.param], fp)

    config = configuration.get_config(cfg.strpath)
    this_app = create_app(config)
    this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://"
    this_app.use_reloader = False
    this_app.config['TESTING'] = True
    ctx = this_app.app_context()
    ctx.push()
    db.create_all()
    username, db_name = str(uuid.uuid4()).replace('-', '_'), str(uuid.uuid4()).replace('-', '_')
    request.cls.app_client = this_app.test_client()
    request.cls.db_name = remove_digits(db_name)
    request.cls.username = remove_digits(username)
    request.cls.backend = request.param
    yield
    if request.param == 'docker':
        delete_all_test_postgraas_container()
    elif request.param == 'pg_cluster':
        try:
            delete_test_database_and_user(db_name, username, dict(config.items('backend')))
        except Exception:
            pass
    db.drop_all()
    ctx.pop()
コード例 #2
0
def parametrized_setup(request, tmpdir):
    from postgraas_server.management_resources import db
    cfg = tmpdir.join('config')
    with open(cfg.strpath, "w") as fp:
        json.dump(CONFIGS[request.param], fp)

    config = configuration.get_config(cfg.strpath)
    this_app = create_app(config)
    this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://"
    this_app.use_reloader = False
    this_app.config['TESTING'] = True
    ctx = this_app.app_context()
    ctx.push()
    db.create_all()
    username, db_name = str(uuid.uuid4()).replace('-', '_'), str(
        uuid.uuid4()).replace('-', '_')
    request.cls.app_client = this_app.test_client()
    request.cls.db_name = remove_digits(db_name)
    request.cls.username = remove_digits(username)
    request.cls.backend = request.param
    yield
    if request.param == 'docker':
        delete_all_test_postgraas_container()
    elif request.param == 'pg_cluster':
        try:
            delete_test_database_and_user(db_name, username,
                                          dict(config.items('backend')))
        except Exception:
            pass
    db.drop_all()
    ctx.pop()
コード例 #3
0
def parametrized_setup(request, tmpdir):
    from postgraas_server.management_resources import db
    config = CONFIGS[request.param]
    this_app = create_app(config)
    this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://"
    this_app.use_reloader = False
    this_app.config['TESTING'] = True
    ctx = this_app.app_context()
    ctx.push()
    db.create_all()
    username, db_name = str(uuid.uuid4()).replace('-', '_'), str(
        uuid.uuid4()).replace('-', '_')
    request.cls.app_client = this_app.test_client()
    request.cls.db_name = remove_digits(db_name)
    request.cls.username = remove_digits(username)
    request.cls.backend = request.param
    yield
    if request.param == 'pg_cluster':
        #        try:
        delete_test_database_and_user(db_name, username, config['backend'])


#        except Exception:
#            pass
    db.drop_all()
    ctx.pop()
コード例 #4
0
    def test_is_sane_database(self):
        from postgraas_server.management_resources import db
        with self.this_app.app_context():
            db.drop_all()
            db.create_all()
            is_sane = is_sane_database(db.Model, db.session)

        self.assertEqual(True, is_sane)
コード例 #5
0
    def test_is_sane_database(self):
        from postgraas_server.management_resources import db
        with self.this_app.app_context():
            db.drop_all()
            db.create_all()
            is_sane = is_sane_database(db.Model, db.session)

        self.assertEqual(True, is_sane)
コード例 #6
0
def init_db(postgraas_app):
    # import all modules here that might define models so that
    # they will be registered properly on the metadata.  Otherwise
    # you will have to import them first before calling init_db()

    from postgraas_server.management_resources import db
    with postgraas_app.app_context():
        if not is_sane_database(db.Model, db.session):
            db.drop_all()
            db.create_all()
コード例 #7
0
def init_db(postgraas_app):
    # import all modules here that might define models so that
    # they will be registered properly on the metadata.  Otherwise
    # you will have to import them first before calling init_db()

    from postgraas_server.management_resources import db
    with postgraas_app.app_context():
        if not is_sane_database(db.Model, db.session):
            db.drop_all()
            db.create_all()
コード例 #8
0
 def setUp(self):
     self.module_path = os.path.abspath(os.path.dirname(__file__))
     self.this_app = create_app(configuration.get_config(os.path.join(self.module_path, 'postgraas_server.cfg')))
     #self.this_app.debug = True
     self.this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://"
     self.this_app.use_reloader = False
     self.this_app.config['TESTING'] = True
     self.app = self.this_app.test_client()
     self.delete_all_test_postgraas_container()
     from postgraas_server.management_resources import db
     with self.this_app.app_context():
         db.drop_all()
         db.create_all()
コード例 #9
0
def docker_setup(request, tmpdir):
    from postgraas_server.management_resources import db
    cfg = tmpdir.join('config')
    with open(cfg.strpath, "w") as fp:
        json.dump(CONFIGS['docker'], fp)

    this_app = create_app(configuration.get_config(cfg.strpath))
    this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://"
    this_app.use_reloader = False
    this_app.config['TESTING'] = True
    ctx = this_app.app_context()
    ctx.push()
    db.create_all()
    request.cls.app_client = this_app.test_client()
    yield
    delete_all_test_postgraas_container()
    db.drop_all()
    ctx.pop()
コード例 #10
0
def docker_setup(request, tmpdir):
    from postgraas_server.management_resources import db
    cfg = tmpdir.join('config')
    with open(cfg.strpath, "w") as fp:
        json.dump(CONFIGS['docker'], fp)

    this_app = create_app(configuration.get_config(cfg.strpath))
    this_app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://"
    this_app.use_reloader = False
    this_app.config['TESTING'] = True
    ctx = this_app.app_context()
    ctx.push()
    db.create_all()
    request.cls.app_client = this_app.test_client()
    yield
    delete_all_test_postgraas_container()
    db.drop_all()
    ctx.pop()
コード例 #11
0
def init_db(db_credentials, postgraas_app):
    # import all modules here that might define models so that
    # they will be registered properly on the metadata.  Otherwise
    # you will have to import them first before calling init_db()
    from postgraas_server.management_resources import db
    with postgraas_app.app_context():
        db.drop_all()
        db.create_all()
        #maybe this is a bad idea?
        #from postgraas_server.management_resources import DBInstance
        #admin = DBInstance(postgraas_instance_name='PostgraasMetaDB',
        #                  db_name=db_credentials["db_name"],
        #                  username=db_credentials["db_username"],
        #                  password=db_credentials["db_pwd"],
        #                  hostname=db_credentials["host"],
        #                  port=db_credentials["port"],
        #                  container_id=db_credentials['container_id'])
        #db.session.add(admin)
        #db.session.commit()