diff --git a/doc/changes/changes_0.10.0.md b/doc/changes/changes_0.10.0.md index 2952522..5a25681 100644 --- a/doc/changes/changes_0.10.0.md +++ b/doc/changes/changes_0.10.0.md @@ -4,6 +4,10 @@ * #98: Updated saas-api to version >1.0,<2.0 and pytest-backend +## Features + +* #107: Add parameter to disable printing the alter session info + ## Dependency Updates Compared to version 0.3.1 this release updates the following dependencies: diff --git a/exasol/python_extension_common/deployment/language_container_deployer.py b/exasol/python_extension_common/deployment/language_container_deployer.py index 687bd02..b3238b8 100644 --- a/exasol/python_extension_common/deployment/language_container_deployer.py +++ b/exasol/python_extension_common/deployment/language_container_deployer.py @@ -147,6 +147,7 @@ def download_and_run( alter_system: bool = True, allow_override: bool = False, wait_for_completion: bool = True, + print_activation_statements: bool = True, ) -> None: """ Downloads the language container from the provided url to a temporary file and then deploys it. @@ -158,6 +159,8 @@ def download_and_run( allow_override - If True the activation of a language container with the same alias will be overriden, otherwise a RuntimeException will be thrown. wait_for_completion - If True will wait until the language container becomes operational. + print_activation_statements - If True and alter_system is False, + it will print the ALTER SESSION command to stdout. """ with tempfile.NamedTemporaryFile() as tmp_file: @@ -171,6 +174,7 @@ def download_and_run( alter_system, allow_override, wait_for_completion, + print_activation_statements, ) def _upload_path(self, bucket_file_path: str | None) -> bfs.path.PathLike: @@ -183,6 +187,7 @@ def run( alter_system: bool = True, allow_override: bool = False, wait_for_completion: bool = True, + print_activation_statements: bool = True, ) -> None: """ Deploys the language container. This includes two steps, both of which are optional: @@ -203,6 +208,8 @@ def run( For this to work either of the two conditions should be met. The pyexasol connection should have an open schema, or The calling user should have a permission to create schema. + print_activation_statements - If True and alter_system is False, + it will print the ALTER SESSION command to stdout. """ if not bucket_file_path: @@ -225,18 +232,18 @@ def run( if container_file and wait_for_completion: self._wait_container_upload_completion(bucket_file_path) - if not alter_system: + if not alter_system and print_activation_statements: message = dedent( f""" - In SQL, you can activate the SLC - by using the following statements: - - To activate the SLC only for the current session: - {self.generate_activation_command(bucket_file_path, LanguageActivationLevel.Session, True)} - - To activate the SLC on the system: - {self.generate_activation_command(bucket_file_path, LanguageActivationLevel.System, True)} - """ + In SQL, you can activate the SLC + by using the following statements: + + To activate the SLC only for the current session: + {self.generate_activation_command(bucket_file_path, LanguageActivationLevel.Session, True)} + + To activate the SLC on the system: + {self.generate_activation_command(bucket_file_path, LanguageActivationLevel.System, True)} + """ ) print(message) diff --git a/test/unit/deployment/test_language_container_deployer.py b/test/unit/deployment/test_language_container_deployer.py index 8c68b33..312aba7 100644 --- a/test/unit/deployment/test_language_container_deployer.py +++ b/test/unit/deployment/test_language_container_deployer.py @@ -230,16 +230,38 @@ def test_slc_deployer_get_language_definition( assert command == expected_command -def mock_deployer(pyexasol_conn, pylanguage_alias, bfs_path): - deployer = LanguageContainerDeployer(pyexasol_conn, language_alias, bfs_path) - deployer.upload_container = Mock() - deployer.activate_container = Mock() - return deployer - - def test_extract_validator_called(sample_bucket_path, container_deployer, container_file): container_deployer.run(container_file, wait_for_completion=True) expected = container_deployer._extract_validator.verify_all_nodes assert expected.called and equal( expected.call_args.args[2], sample_bucket_path / container_file.name ) + + +@pytest.mark.parametrize( + "alter_system, print_activation_statements, invocation_generate_activation_command_expected", + [ + (False, True, True), + (True, True, False), + (False, False, False), + (True, False, False), + ], +) +def test_print_alter_session_activation( + container_deployer, + container_file, + alter_system, + print_activation_statements, + invocation_generate_activation_command_expected, +): + container_deployer.generate_activation_command = MagicMock() + container_deployer.run( + container_file, + wait_for_completion=True, + alter_system=alter_system, + print_activation_statements=print_activation_statements, + ) + assert ( + container_deployer.generate_activation_command.called + == invocation_generate_activation_command_expected + )