|
12 | 12 | _build_list_preprocessors_query, |
13 | 13 | _build_preview_query, |
14 | 14 | _build_profile_select, |
| 15 | + _build_profile_status_query, |
15 | 16 | _build_set_preprocessor_query, |
16 | 17 | _build_stats_query, |
17 | 18 | _build_top_values_query, |
@@ -387,6 +388,45 @@ def test_build_profile_select(): |
387 | 388 | assert sql == expected |
388 | 389 |
|
389 | 390 |
|
| 391 | +def test_build_profile_status_query(): |
| 392 | + sql = collapse_spaces(_build_profile_status_query()) |
| 393 | + expected = collapse_spaces(""" |
| 394 | + SELECT "SESSION_VALUE" |
| 395 | + FROM "SYS"."EXA_PARAMETERS" |
| 396 | + WHERE "PARAMETER_NAME" = 'PROFILE' |
| 397 | + """) |
| 398 | + assert sql == expected |
| 399 | + |
| 400 | + |
| 401 | +def _make_profile_server(profile_already_on: bool): |
| 402 | + connection = MagicMock() |
| 403 | + connection.execute_query.return_value.fetchval.return_value = ( |
| 404 | + "ON" if profile_already_on else "OFF" |
| 405 | + ) |
| 406 | + connection.execute_query.return_value.fetchall.return_value = [] |
| 407 | + config = MagicMock() |
| 408 | + config.enable_query_profiling = True |
| 409 | + server = ExasolMCPServer(connection=connection, config=config) |
| 410 | + return server, connection |
| 411 | + |
| 412 | + |
| 413 | +def test_profile_query_enables_and_disables_profiling_when_off(): |
| 414 | + server, connection = _make_profile_server(profile_already_on=False) |
| 415 | + server.profile_query("SELECT 1") |
| 416 | + calls = [str(c) for c in connection.execute_query.call_args_list] |
| 417 | + statements = connection.execute_query.call_args_list[-1][0][0] |
| 418 | + assert statements[0] == "ALTER SESSION SET PROFILE = 'ON'" |
| 419 | + assert statements[-2] == "ALTER SESSION SET PROFILE = 'OFF'" |
| 420 | + |
| 421 | + |
| 422 | +def test_profile_query_skips_profile_toggle_when_already_on(): |
| 423 | + server, connection = _make_profile_server(profile_already_on=True) |
| 424 | + server.profile_query("SELECT 1") |
| 425 | + statements = connection.execute_query.call_args_list[-1][0][0] |
| 426 | + assert "ALTER SESSION SET PROFILE = 'ON'" not in statements |
| 427 | + assert "ALTER SESSION SET PROFILE = 'OFF'" not in statements |
| 428 | + |
| 429 | + |
390 | 430 | def test_build_list_preprocessors_query(): |
391 | 431 | sql = collapse_spaces(_build_list_preprocessors_query()) |
392 | 432 | expected = collapse_spaces(""" |
|
0 commit comments