Skip to content

#107: Add parameter to disable printing the alter session info #108

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

Merged
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
4 changes: 4 additions & 0 deletions doc/changes/changes_0.10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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)

Expand Down
36 changes: 29 additions & 7 deletions test/unit/deployment/test_language_container_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Comment on lines -233 to -238
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used anywhere. I suspect that it was replaced by the fixture at line 71 at some point, but not removed here.


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
)