Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for configuration #133

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ markers = [
"context_managers: tests related to pyexasol context_managers.",
"metadata: tests related to metadata retrieval with pyexasol.",
"json: tests related to json serialization in pyexasol.",
"dbapi2: tests related to dbapi2 compatibility."
"dbapi2: tests related to dbapi2 compatibility.",
"configuration: tests related to pyexasol settings and configuration."
]

120 changes: 120 additions & 0 deletions test/integration/dsn_test.py
Nicoretti marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import pytest

from pyexasol import ExaConnectionError


@pytest.mark.configuration
def test_ip_range_with_custom_Port(connection):
dsn = "127.0.0.10..19:8564"
expected = {
("127.0.0.10", "127.0.0.10", 8564, None),
("127.0.0.11", "127.0.0.11", 8564, None),
("127.0.0.12", "127.0.0.12", 8564, None),
("127.0.0.13", "127.0.0.13", 8564, None),
("127.0.0.14", "127.0.0.14", 8564, None),
("127.0.0.15", "127.0.0.15", 8564, None),
("127.0.0.16", "127.0.0.16", 8564, None),
("127.0.0.17", "127.0.0.17", 8564, None),
("127.0.0.18", "127.0.0.18", 8564, None),
("127.0.0.19", "127.0.0.19", 8564, None),
}
actual = set(connection._process_dsn(dsn))
assert actual == expected


@pytest.mark.configuration
def test_multiple_ranges_with_multiple_ports_and_default_port_at_the_end(connection):
dsn = "127.0.0.10..19:8564,127.0.0.20,localhost:8565,127.0.0.21..23"
expected = {
("127.0.0.10", "127.0.0.10", 8564, None),
("127.0.0.11", "127.0.0.11", 8564, None),
("127.0.0.12", "127.0.0.12", 8564, None),
("127.0.0.13", "127.0.0.13", 8564, None),
("127.0.0.14", "127.0.0.14", 8564, None),
("127.0.0.15", "127.0.0.15", 8564, None),
("127.0.0.16", "127.0.0.16", 8564, None),
("127.0.0.17", "127.0.0.17", 8564, None),
("127.0.0.18", "127.0.0.18", 8564, None),
("127.0.0.19", "127.0.0.19", 8564, None),
("127.0.0.20", "127.0.0.20", 8565, None),
("127.0.0.21", "127.0.0.21", 8563, None),
("127.0.0.22", "127.0.0.22", 8563, None),
("127.0.0.23", "127.0.0.23", 8563, None),
("localhost", "127.0.0.1", 8565, None),
}
actual = set(connection._process_dsn(dsn))
assert actual == expected


@pytest.mark.configuration
def test_multiple_ranges_with_fingerprint_and_port(connection):
dsn = "127.0.0.10..19/ABC,127.0.0.20,localhost/CDE:8564"
expected = {
("127.0.0.11", "127.0.0.11", 8564, "ABC"),
("127.0.0.19", "127.0.0.19", 8564, "ABC"),
("127.0.0.20", "127.0.0.20", 8564, "CDE"),
("127.0.0.17", "127.0.0.17", 8564, "ABC"),
("localhost", "127.0.0.1", 8564, "CDE"),
("127.0.0.12", "127.0.0.12", 8564, "ABC"),
("127.0.0.15", "127.0.0.15", 8564, "ABC"),
("127.0.0.14", "127.0.0.14", 8564, "ABC"),
("127.0.0.13", "127.0.0.13", 8564, "ABC"),
("127.0.0.16", "127.0.0.16", 8564, "ABC"),
("127.0.0.10", "127.0.0.10", 8564, "ABC"),
("127.0.0.18", "127.0.0.18", 8564, "ABC"),
}
actual = set(connection._process_dsn(dsn))
assert actual == expected


@pytest.mark.configuration
def test_empty_dsn(connection):
dsn = " "
with pytest.raises(ExaConnectionError) as excinfo:
connection._process_dsn(dsn)

expected = "Connection string is empty"
actual = excinfo.value.message
assert actual == expected


@pytest.mark.configuration
def test_invalid_range(connection):
dsn = "127.0.0.15..10"
with pytest.raises(ExaConnectionError) as excinfo:
connection._process_dsn(dsn)

expected = (
"Connection string part [127.0.0.15..10] contains an invalid range, "
"lower bound is higher than upper bound"
)
actual = excinfo.value.message
assert actual == expected


@pytest.mark.configuration
def test_hostname_cannot_be_resolved(connection):
dsn = "test1..5.zlan"
with pytest.raises(ExaConnectionError) as excinfo:
connection._process_dsn(dsn)

expected = (
"Could not resolve IP address of hostname "
"[test1.zlan] derived from connection string"
)
actual = excinfo.value.message
assert actual == expected


@pytest.mark.configuration
def test_hostname_range_with_zero_padding(connection):
dsn = "test01..20.zlan"
with pytest.raises(ExaConnectionError) as excinfo:
connection._process_dsn(dsn)

expected = (
"Could not resolve IP address of hostname "
"[test01.zlan] derived from connection string"
)
actual = excinfo.value.message
assert actual == expected
36 changes: 36 additions & 0 deletions test/integration/local_config_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
import pyexasol
from inspect import cleandoc


@pytest.fixture
def config(dsn, user, password, schema):
yield cleandoc(f"""
[pyexasol]
dsn = {dsn}
user = {user}
password = {password}
schema = {schema}
compression = True
encryption = False
socket_timeout = 20
""")


@pytest.fixture
def config_file(tmpdir, config):
path = tmpdir / "pyexasol.ini"
with open(path, "w", encoding="utf-8") as f:
f.write(config)
yield path


@pytest.mark.configuration
def test_connect_using_config(config_file):
connection = pyexasol.connect_local_config(
config_section="pyexasol", config_path=config_file
)
result = connection.execute("SELECT 1;")
expected = [(1,)]
actual = result.fetchall()
assert expected == actual
42 changes: 42 additions & 0 deletions test/integration/session_params_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest
import pyexasol
from importlib.metadata import version


@pytest.fixture
def pyexasol_version():
yield version("pyexasol")


@pytest.fixture
def session_info_query():
yield "SELECT * FROM EXA_DBA_SESSIONS WHERE session_id=CURRENT_SESSION"


@pytest.mark.configuration
def test_default_session_parameters(connection, session_info_query, pyexasol_version):
expected = {f"PyEXASOL {pyexasol_version}"}
actual = set(connection.execute(session_info_query).fetchone())
assert actual >= expected


@pytest.mark.configuration
def test_modified_session_parameters(
dsn, user, password, schema, connection, session_info_query
):
client_name = "MyCustomClient"
client_version = "1.2.3"
client_os_username = "small_cat"
connection = pyexasol.connect(
dsn=dsn,
user=user,
password=password,
schema=schema,
client_name=client_name,
client_version=client_version,
client_os_username=client_os_username,
)

expected = {f"{client_name} {client_version}", client_os_username}
actual = set(connection.execute(session_info_query).fetchone())
assert actual >= expected
Loading