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()
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()
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()
    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)
    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)
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()
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()
 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()
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()
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()
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()
 def tearDown(self):
     from postgraas_server.management_resources import db
     with self.this_app.app_context():
         db.drop_all()
 def tearDown(self):
     from postgraas_server.management_resources import db
     with self.this_app.app_context():
         db.drop_all()
 def tearDown(self):
     self.delete_all_test_postgraas_container()
     from postgraas_server.management_resources import db
     with self.this_app.app_context():
         db.drop_all()