Example #1
0
def apply_database_plumbing(request, postgresql_proc):
    """Bolt pytest-dbfixtures onto Django to work around its lack of no-setup testing facilities."""
    psycopg2, config = try_import('psycopg2', request)
    settings.DATABASES['default'].update({
        'NAME': config.postgresql.db,
        'USER': config.postgresql.user,
        'HOST': postgresql_proc.host,
        'PORT': postgresql_proc.port,
    })
    init_postgresql_database(psycopg2, config.postgresql.user, postgresql_proc.host, postgresql_proc.port,
                             config.postgresql.db)
Example #2
0
def pg_connection(request, postgresql_proc):
    psycopg2, config = try_import('psycopg2', request)
    pg_host = postgresql_proc.host
    pg_port = postgresql_proc.port
    pg_db = config.postgresql.db

    init_postgresql_database(psycopg2, config.postgresql.user, pg_host, pg_port, pg_db)
    apply_migrations(config.postgresql.user, pg_host, pg_port, pg_db)
    conn = psycopg2.connect(dbname=pg_db, user=config.postgresql.user,
                            host=pg_host, port=pg_port)
    return conn
Example #3
0
def apply_database_plumbing(request, postgresql_proc):
    """Bolt pytest-dbfixtures onto Django to work around its lack of no-setup testing facilities."""
    psycopg2, config = try_import('psycopg2', request)
    settings.DATABASES['default'].update({
        'NAME': config.postgresql.db,
        'USER': config.postgresql.user,
        'HOST': postgresql_proc.host,
        'PORT': postgresql_proc.port,
    })
    init_postgresql_database(psycopg2, config.postgresql.user,
                             postgresql_proc.host, postgresql_proc.port,
                             config.postgresql.db)
Example #4
0
def database(request):
    config = get_config(request)
    pg_host = config.postgresql.host
    pg_port = config.postgresql.port
    pg_user = config.postgresql.user
    pg_db = config.postgresql.db

    # Create our Database.
    init_postgresql_database(psycopg2, pg_user, pg_host, pg_port, pg_db)

    # Ensure our database gets deleted.
    @request.addfinalizer
    def drop_database():
        drop_postgresql_database(psycopg2, pg_user, pg_host, pg_port, pg_db)

    return "postgresql://{}@{}:{}/{}".format(pg_user, pg_host, pg_port, pg_db)
Example #5
0
def database(request):
    config = get_config(request)
    pg_host = config.postgresql.host
    pg_port = config.postgresql.port
    pg_user = config.postgresql.user
    pg_db = config.postgresql.db

    # Create our Database.
    init_postgresql_database(psycopg2, pg_user, pg_host, pg_port, pg_db)

    # Ensure our database gets deleted.
    @request.addfinalizer
    def drop_database():
        drop_postgresql_database(psycopg2, pg_user, pg_host, pg_port, pg_db)

    return "postgresql://{}@{}:{}/{}".format(pg_user, pg_host, pg_port, pg_db)