def database(request): config = get_config(request) pg_host = config.get("host") pg_port = config.get("port") or os.environ.get("PGPORT", 5432) pg_user = config.get("user") pg_db = config.get("db", "tests") pg_version = config.get("version", 10.1) janitor = DatabaseJanitor(pg_user, pg_host, pg_port, pg_db, pg_version) # In case the database already exists, possibly due to an aborted test run, # attempt to drop it before creating try: janitor.drop() except InvalidCatalogName: # We can safely ignore this exception as that means there was # no leftover database pass # Create our Database. janitor.init() # Ensure our database gets deleted. @request.addfinalizer def drop_database(): janitor.drop() return "postgresql://{}@{}:{}/{}".format(pg_user, pg_host, pg_port, pg_db)
def database(request): ''' Create a Postgres database for the tests, and drop it when the tests are done. ''' pg_host = DB_OPTS.get("host") pg_port = DB_OPTS.get("port") pg_user = DB_OPTS.get("username") pg_pass = DB_OPTS.get("password") pg_db = DB_OPTS["database"] janitor = DatabaseJanitor(pg_user, pg_host, pg_port, pg_db, 9.6, pg_pass) janitor.init() yield janitor.drop()
def database(request): ''' Create a Postgres database for the tests, and drop it when the tests are done. ''' pg_host = DB_OPTS.get("host") pg_port = DB_OPTS.get("port") pg_user = DB_OPTS.get("username") pg_pass = DB_OPTS.get("password") pg_db = DB_OPTS["database"] db_janitor = DatabaseJanitor(pg_user, pg_host, pg_port, pg_db, 12, pg_pass) db_janitor.init() @request.addfinalizer def drop_database(): db_janitor.drop()
def database(postgresql_proc): """Initialize a test postgres database.""" janitor = DatabaseJanitor( postgresql_proc.user, postgresql_proc.host, postgresql_proc.port, postgresql_proc.dbname, postgresql_proc.version, postgresql_proc.password, ) janitor.init() with janitor.cursor() as cur: cur.execute("""\ CREATE TABLE my_source_1 (id serial PRIMARY KEY, num integer); CREATE TABLE my_source_2 (id serial PRIMARY KEY, num integer); """) yield postgresql_proc janitor.drop()
def config_database(request): connection_template = 'postgresql+psycopg2://{0}:{1}@{2}:{3}/{4}' pg_host = os.environ.get('POSTGRES_HOST', 'db') pg_port = os.environ.get('POSTGRES_PORT', 5432) pg_user = os.environ.get('POSTGRES_USER', 'tests') pg_passsword = os.environ.get('POSTGRES_PASSWORD', 'tests') pg_db = os.environ.get('POSTGRES_DB', 'tests') connection_string = connection_template.format(pg_user, pg_passsword, pg_host, pg_port, pg_db) # Create the database janitor = DatabaseJanitor(pg_user, pg_host, pg_port, pg_db, '11', pg_passsword) janitor.init() yield connection_string # Ensure the database gets deleted janitor.drop()
def database(request): config = get_config(request) pg_host = config.get("host") pg_port = config.get("port") or os.environ.get("PGPORT", 5432) pg_user = config.get("user") pg_db = config.get("db", "tests") pg_version = config.get("version", 10.1) janitor = DatabaseJanitor(pg_user, pg_host, pg_port, pg_db, pg_version) # In case the database already exists, possibly due to an aborted test run, # attempt to drop it before creating janitor.drop() # Create our Database. janitor.init() # Ensure our database gets deleted. @request.addfinalizer def drop_database(): janitor.drop() return "postgresql://{}@{}:{}/{}".format(pg_user, pg_host, pg_port, pg_db)