コード例 #1
0
def test_failed_connection_postgres():
    """ First and second host:port fail, an Exception is raised."""
    with pytest.raises(Exception) as err:
        with patch("psycopg2.connect") as mocked_conn:
            mocked_conn.side_effect = [
                psycopg2.OperationalError, psycopg2.OperationalError
            ]
            with get("postgres_multi_server") as conn:
                pass
    assert str(err.value) == "Could not connect to postgres_multi_server"
コード例 #2
0
def test_simple_postgres():
    """ Test connection to postgres."""
    with patch("psycopg2.connect") as mocked_conn:

        with get("postgres_simple") as conn:
            pass

    mocked_conn.assert_called_with("host=127.0.0.1 port=5436",
                                   dbname=None,
                                   password="******",
                                   user="******")
    conn.close.assert_called()
コード例 #3
0
def test_multi_server_exasol():
    """ Test passing exasol multiple connections."""
    with patch("pyexasol.connect") as mocked_conn:

        with get("exasol_multi_server") as conn:
            pass
    mocked_conn.assert_called_with(
        compression=True,
        dsn="127.0.0.1:5436,127.0.0.2:5437",
        fetch_dict=True,
        password="******",
        schema="s",
        user="******",
    )
    conn.close.assert_called()
コード例 #4
0
def test_multi_server_postgres():
    """ First host:port fails, handle failover."""
    with patch("psycopg2.connect") as mocked_conn:
        mocked_conn.side_effect = [psycopg2.OperationalError, ConnectionMock()]

        with get("postgres_multi_server") as conn:
            pass

    mocked_conn.assert_has_calls([
        call(
            "host=127.0.0.1 port=5436",
            dbname=None,
            password="******",
            user="******",
        ),
        call(
            "host=127.0.0.2 port=5436",
            dbname=None,
            password="******",
            user="******",
        ),
    ])
    conn.close.assert_called()
コード例 #5
0
def test_disabled_connection():
    """ Disabled connections are not handled."""
    with pytest.raises(KeyError):
        with get("postgres_disabled") as connection:
            assert not connection
コード例 #6
0
def test_bad_dsn_exasol():
    """ Test passing exasol a bad dsn."""
    with pytest.raises(pyexasol.exceptions.ExaConnectionDsnError):
        with get("exasol_bad_dsn"):
            pass