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 test for connecting via proxy #140

Merged
merged 2 commits into from
Jun 21, 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
6 changes: 3 additions & 3 deletions test/integration/metadata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ def test_list_objects(connection):

@pytest.mark.metadata
def test_list_object_sizes(connection):
expected = [709780]
actual = [
sizes = [
db_object["MEM_OBJECT_SIZE"]
for db_object in connection.meta.list_object_sizes(
object_name_pattern="USERS%", object_type_pattern="TABLE"
)
]
assert actual == expected
do_all_objects_have_a_size = all(map(lambda size: size != 0, sizes))
assert do_all_objects_have_a_size


@pytest.mark.metadata
Expand Down
69 changes: 69 additions & 0 deletions test/integration/proxy_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import pytest
import pyexasol
import subprocess
import platform


@pytest.fixture
def proxy_port():
yield 8562


@pytest.fixture
def proxy(proxy_port):
os_specific_flags = ["--reuse"] if platform.system() == "Linux" else []
command = ["pproxy", "-l", f"http://:{proxy_port}/"] + os_specific_flags
pproxy = subprocess.Popen(command)

yield f"http://127.0.0.1:{proxy_port}"

pproxy.kill()


@pytest.fixture
def proxy_user():
yield "johndoe"


@pytest.fixture
def proxy_password():
yield "JohndoesPassword"


@pytest.fixture
def proxy_with_auth(proxy_port, proxy_user, proxy_password):
os_specific_flags = ["--reuse"] if platform.system() == "Linux" else []
command = [
"pproxy",
"-l",
f"http://:{proxy_port}/#{proxy_user}:{proxy_password}",
] + os_specific_flags
pproxy = subprocess.Popen(command)

yield f"http://{proxy_user}:{proxy_password}@localhost:{proxy_port}"

pproxy.kill()


@pytest.mark.configuration
def test_connect_through_proxy(dsn, user, password, schema, proxy):
with pyexasol.connect(
dsn=dsn, user=user, password=password, schema=schema, http_proxy=proxy
) as connection:
result = connection.execute("SELECT 1;")
expected = 1
actual = result.fetchval()
assert expected == actual


@pytest.mark.configuration
def test_connect_through_proxy_with_authentication(
dsn, user, password, schema, proxy_with_auth
):
with pyexasol.connect(
dsn=dsn, user=user, password=password, schema=schema, http_proxy=proxy_with_auth
) as connection:
result = connection.execute("SELECT 1;")
expected = 1
actual = result.fetchval()
assert expected == actual
Loading