def test_executor_init_with_password(request):
    """Test whether the executor initializes properly."""
    config = get_config(request)
    executor = PostgreSQLExecutor(
        executable=config['exec'],
        host=config['host'],
        port=get_port(config['port']),
        datadir='/tmp/error',
        unixsocketdir=config['unixsocketdir'],
        logfile='/tmp/version.error.log',
        startparams=config['startparams'],
        password="******",
    )
    with executor:
        assert executor.running()
        psycopg2.connect(dbname=executor.user,
                         user=executor.user,
                         password=executor.password,
                         host=executor.host,
                         port=executor.port)
        with pytest.raises(psycopg2.OperationalError):
            psycopg2.connect(dbname=executor.user,
                             user=executor.user,
                             password='******',
                             host=executor.host,
                             port=executor.port)
    assert not executor.running()
Exemple #2
0
def test_proc_with_password(
    postgres_with_password: PostgreSQLExecutor, ) -> None:
    """Check that password option to postgresql_proc factory is honored."""
    assert postgres_with_password.running() is True

    # no assertion necessary here; we just want to make sure it connects with
    # the password
    retry(
        lambda: psycopg.connect(
            dbname=postgres_with_password.user,
            user=postgres_with_password.user,
            password=postgres_with_password.password,
            host=postgres_with_password.host,
            port=postgres_with_password.port,
        ),
        possible_exception=psycopg.OperationalError,
    )

    with pytest.raises(psycopg.OperationalError):
        psycopg.connect(
            dbname=postgres_with_password.user,
            user=postgres_with_password.user,
            password="******",
            host=postgres_with_password.host,
            port=postgres_with_password.port,
        )
Exemple #3
0
def test_executor_init_with_password(
    request: FixtureRequest,
    monkeypatch: pytest.MonkeyPatch,
    tmp_path_factory: pytest.TempPathFactory,
    locale: str,
) -> None:
    """Test whether the executor initializes properly."""
    config = get_config(request)
    monkeypatch.setenv("LC_ALL", locale)
    port = get_port(config["port"])
    assert port is not None
    tmpdir = tmp_path_factory.mktemp(f"pytest-postgresql-{request.node.name}")
    datadir = tmpdir / f"data-{port}"
    datadir.mkdir()
    logfile_path = tmpdir / f"postgresql.{port}.log"
    executor = PostgreSQLExecutor(
        executable=config["exec"],
        host=config["host"],
        port=port,
        datadir=str(datadir),
        unixsocketdir=config["unixsocketdir"],
        logfile=str(logfile_path),
        startparams=config["startparams"],
        password="******",
        dbname="somedatabase",
    )
    with executor:
        assert executor.running()
        psycopg.connect(
            dbname=executor.user,
            user=executor.user,
            password=executor.password,
            host=executor.host,
            port=executor.port,
        )
        with pytest.raises(psycopg.OperationalError):
            psycopg.connect(
                dbname=executor.user,
                user=executor.user,
                password="******",
                host=executor.host,
                port=executor.port,
            )
    assert not executor.running()
Exemple #4
0
def test_postgresql_proc(postgresql_proc: PostgreSQLExecutor) -> None:
    """Test different postgresql versions."""
    assert postgresql_proc.running() is True