diff --git a/test/integration/test_sagemaker_extension_wrapper.py b/test/integration/test_sagemaker_extension_wrapper.py index 059e377..9088f1c 100644 --- a/test/integration/test_sagemaker_extension_wrapper.py +++ b/test/integration/test_sagemaker_extension_wrapper.py @@ -7,7 +7,8 @@ activate_languages, assert_connection_exists, assert_run_empty_udf, - get_script_counts + get_script_counts, + set_language_definition, ) @@ -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) diff --git a/test/integration/test_transformers_extension_wrapper.py b/test/integration/test_transformers_extension_wrapper.py index 4f60cf8..991669a 100644 --- a/test/integration/test_transformers_extension_wrapper.py +++ b/test/integration/test_transformers_extension_wrapper.py @@ -10,7 +10,8 @@ activate_languages, assert_connection_exists, assert_run_empty_udf, - get_script_counts + get_script_counts, + set_language_definition, ) @@ -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) diff --git a/test/unit/test_extension_wrapper_common.py b/test/unit/test_extension_wrapper_common.py index 9080589..343477e 100644 --- a/test/unit/test_extension_wrapper_common.py +++ b/test/unit/test_extension_wrapper_common.py @@ -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') @@ -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'] @@ -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): diff --git a/test/utils/integration_test_utils.py b/test/utils/integration_test_utils.py index 2a31673..92be5a0 100644 --- a/test/utils/integration_test_utils.py +++ b/test/utils/integration_test_utils.py @@ -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)