Skip to content

Commit

Permalink
Add test for connecting via proxy (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti authored Jun 21, 2024
1 parent f730bb9 commit 8803d0c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
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

0 comments on commit 8803d0c

Please sign in to comment.