Skip to content

Commit

Permalink
#133 Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Sep 4, 2024
1 parent 9b7c372 commit 5cacaee
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
13 changes: 9 additions & 4 deletions test/integration/test_sagemaker_extension_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
activate_languages,
assert_connection_exists,
assert_run_empty_udf,
get_script_counts
get_script_counts,
set_language_definition,
)


Expand All @@ -22,10 +23,14 @@ def test_initialize_sme_extension(
secrets.save(CKey.aws_access_key_id, "FAKEKEYIDDONTUSEIT")
secrets.save(CKey.aws_secret_access_key, "FakeSecretAccessKeyDontTryToUseIt")

# Run the extension deployment.
initialize_sme_extension(secrets)

with open_pyexasol_connection(secrets) as pyexasol_connection:
# Set pre-existing language definition with the chosen alias.
language_alias = 'PYTHON3_SME'
set_language_definition(language_alias, pyexasol_connection)

# Run the extension deployment.
initialize_sme_extension(secrets, language_alias=language_alias)

activate_languages(pyexasol_connection, secrets)
assert_run_empty_udf("PYTHON3_SME", pyexasol_connection, secrets)
script_counts = get_script_counts(pyexasol_connection, secrets)
Expand Down
6 changes: 5 additions & 1 deletion test/integration/test_transformers_extension_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
activate_languages,
assert_connection_exists,
assert_run_empty_udf,
get_script_counts
get_script_counts,
set_language_definition,
)


Expand All @@ -26,6 +27,9 @@ def test_initialize_te_extension(

with open_pyexasol_connection(secrets) as pyexasol_connection:

# Set pre-existing language definition with the chosen alias.
set_language_definition(language_alias, pyexasol_connection)

# Run the extension deployment.
initialize_te_extension(secrets, language_alias=language_alias)

Expand Down
29 changes: 27 additions & 2 deletions test/unit/test_extension_wrapper_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
from exasol.nb_connector.ai_lab_config import AILabConfig as CKey
from exasol.nb_connector.extension_wrapper_common import encapsulate_bucketfs_credentials

DB_HOST = '1.2.3.4'


@pytest.fixture
def filled_secrets(secrets) -> Secrets:
secrets.save(CKey.db_host_name, 'localhost')
secrets.save(CKey.db_host_name, DB_HOST)
secrets.save(CKey.db_port, '8888')
secrets.save(CKey.db_user, 'user')
secrets.save(CKey.db_password, 'password')
Expand Down Expand Up @@ -61,7 +63,7 @@ def test_bucketfs_credentials_default(mock_connect, filled_secrets):
query_params = mock_connection.execute.call_args_list[0].kwargs['query_params']
validate_params(query_params['BUCKETFS_ADDRESS'], (
['backend', 'url', 'service_name', 'bucket_name', 'path'],
['onprem', 'https://localhost:6666', 'bfsdefault', 'default', path_in_bucket]
['onprem', f'https://{DB_HOST}:6666', 'bfsdefault', 'default', path_in_bucket]
))
validate_params(query_params['BUCKETFS_USER'], (
['username'], ['user']
Expand All @@ -71,6 +73,29 @@ def test_bucketfs_credentials_default(mock_connect, filled_secrets):
))


def test_bucketfs_credentials_internal(mock_connect, filled_secrets):

path_in_bucket = 'location'
internal_host = 'localhost'
internal_port = 3377
filled_secrets.save(CKey.bfs_internal_host_name, internal_host)
filled_secrets.save(CKey.bfs_internal_port, str(internal_port))

mock_connection = unittest.mock.MagicMock()
mock_connection.__enter__.return_value = mock_connection
mock_connect.return_value = mock_connection

encapsulate_bucketfs_credentials(filled_secrets, path_in_bucket=path_in_bucket,
connection_name='whatever')

mock_connection.execute.assert_called_once()
query_params = mock_connection.execute.call_args_list[0].kwargs['query_params']
validate_params(query_params['BUCKETFS_ADDRESS'], (
['backend', 'url', 'service_name', 'bucket_name', 'path'],
['onprem', f'https://{internal_host}:{internal_port}', 'bfsdefault', 'default', path_in_bucket]
))


@unittest.mock.patch("pyexasol.connect")
def test_bucketfs_credentials_verify(mock_connect, filled_secrets):

Expand Down
9 changes: 9 additions & 0 deletions test/utils/integration_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ def assert_connection_exists(
"""
).fetchall()
assert result


def set_language_definition(language_alias: str, pyexasol_connection: ExaConnection
) -> None:
for alter_type in ['SYSTEM', 'SESSION']:
sql = (f"ALTER {alter_type} SET SCRIPT_LANGUAGES='PYTHON=builtin_python "
"R=builtin_r JAVA=builtin_java PYTHON3=builtin_python3 "
f"{language_alias}=builtin_python3';")
pyexasol_connection.execute(sql)

0 comments on commit 5cacaee

Please sign in to comment.