Skip to content

Commit 5bf60da

Browse files
authored
#107: Add parameter to disable printing the alter session info (#108)
fixes #107
1 parent c67152f commit 5bf60da

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

doc/changes/changes_0.10.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
* #98: Updated saas-api to version >1.0,<2.0 and pytest-backend
66

7+
## Features
8+
9+
* #107: Add parameter to disable printing the alter session info
10+
711
## Dependency Updates
812

913
Compared to version 0.3.1 this release updates the following dependencies:

exasol/python_extension_common/deployment/language_container_deployer.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def download_and_run(
147147
alter_system: bool = True,
148148
allow_override: bool = False,
149149
wait_for_completion: bool = True,
150+
print_activation_statements: bool = True,
150151
) -> None:
151152
"""
152153
Downloads the language container from the provided url to a temporary file and then deploys it.
@@ -158,6 +159,8 @@ def download_and_run(
158159
allow_override - If True the activation of a language container with the same alias will be
159160
overriden, otherwise a RuntimeException will be thrown.
160161
wait_for_completion - If True will wait until the language container becomes operational.
162+
print_activation_statements - If True and alter_system is False,
163+
it will print the ALTER SESSION command to stdout.
161164
"""
162165

163166
with tempfile.NamedTemporaryFile() as tmp_file:
@@ -171,6 +174,7 @@ def download_and_run(
171174
alter_system,
172175
allow_override,
173176
wait_for_completion,
177+
print_activation_statements,
174178
)
175179

176180
def _upload_path(self, bucket_file_path: str | None) -> bfs.path.PathLike:
@@ -183,6 +187,7 @@ def run(
183187
alter_system: bool = True,
184188
allow_override: bool = False,
185189
wait_for_completion: bool = True,
190+
print_activation_statements: bool = True,
186191
) -> None:
187192
"""
188193
Deploys the language container. This includes two steps, both of which are optional:
@@ -203,6 +208,8 @@ def run(
203208
For this to work either of the two conditions should be met.
204209
The pyexasol connection should have an open schema, or
205210
The calling user should have a permission to create schema.
211+
print_activation_statements - If True and alter_system is False,
212+
it will print the ALTER SESSION command to stdout.
206213
"""
207214

208215
if not bucket_file_path:
@@ -225,18 +232,18 @@ def run(
225232
if container_file and wait_for_completion:
226233
self._wait_container_upload_completion(bucket_file_path)
227234

228-
if not alter_system:
235+
if not alter_system and print_activation_statements:
229236
message = dedent(
230237
f"""
231-
In SQL, you can activate the SLC
232-
by using the following statements:
233-
234-
To activate the SLC only for the current session:
235-
{self.generate_activation_command(bucket_file_path, LanguageActivationLevel.Session, True)}
236-
237-
To activate the SLC on the system:
238-
{self.generate_activation_command(bucket_file_path, LanguageActivationLevel.System, True)}
239-
"""
238+
In SQL, you can activate the SLC
239+
by using the following statements:
240+
241+
To activate the SLC only for the current session:
242+
{self.generate_activation_command(bucket_file_path, LanguageActivationLevel.Session, True)}
243+
244+
To activate the SLC on the system:
245+
{self.generate_activation_command(bucket_file_path, LanguageActivationLevel.System, True)}
246+
"""
240247
)
241248
print(message)
242249

test/unit/deployment/test_language_container_deployer.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,38 @@ def test_slc_deployer_get_language_definition(
230230
assert command == expected_command
231231

232232

233-
def mock_deployer(pyexasol_conn, pylanguage_alias, bfs_path):
234-
deployer = LanguageContainerDeployer(pyexasol_conn, language_alias, bfs_path)
235-
deployer.upload_container = Mock()
236-
deployer.activate_container = Mock()
237-
return deployer
238-
239-
240233
def test_extract_validator_called(sample_bucket_path, container_deployer, container_file):
241234
container_deployer.run(container_file, wait_for_completion=True)
242235
expected = container_deployer._extract_validator.verify_all_nodes
243236
assert expected.called and equal(
244237
expected.call_args.args[2], sample_bucket_path / container_file.name
245238
)
239+
240+
241+
@pytest.mark.parametrize(
242+
"alter_system, print_activation_statements, invocation_generate_activation_command_expected",
243+
[
244+
(False, True, True),
245+
(True, True, False),
246+
(False, False, False),
247+
(True, False, False),
248+
],
249+
)
250+
def test_print_alter_session_activation(
251+
container_deployer,
252+
container_file,
253+
alter_system,
254+
print_activation_statements,
255+
invocation_generate_activation_command_expected,
256+
):
257+
container_deployer.generate_activation_command = MagicMock()
258+
container_deployer.run(
259+
container_file,
260+
wait_for_completion=True,
261+
alter_system=alter_system,
262+
print_activation_statements=print_activation_statements,
263+
)
264+
assert (
265+
container_deployer.generate_activation_command.called
266+
== invocation_generate_activation_command_expected
267+
)

0 commit comments

Comments
 (0)