ClickHouse/tests/integration/test_settings_from_server/test.py
Michael Kolupaev fd41df296e drop user
2024-10-29 19:56:38 +00:00

54 lines
2.0 KiB
Python

import pytest
from helpers.client import QueryRuntimeException
from helpers.cluster import ClickHouseCluster
from helpers.network import PartitionManager
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance(
"node",
main_configs=[],
user_configs=[
"configs/users.d/users.xml",
],
)
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_settings_from_server(started_cluster):
# Setting changed by server (default user).
res = node.query("select 42::UInt64 as x format JSON")
assert '"x": 42' in res, "should be unquoted"
# Setting changed by server to a different value (other user).
res = node.query("select 42::UInt64 as x format JSON", user='second_user')
assert '"x": "42"' in res, "should be quoted"
# Setting not changed by server (default user).
res = node.query("select 42::UInt64 as x format JSONEachRow")
assert '[' not in res, "should not be formatted as a JSON array"
# Setting changed by server (other user).
res = node.query("select 42::UInt64 as x format JSONEachRow", user='second_user')
assert '[' in res, "should be formatted as a JSON array"
# Setting changed by server but changed back by the query.
res = node.query("select 42::UInt64 as x settings output_format_json_array_of_rows=0 format JSONEachRow", user='second_user')
assert '[' not in res, "should not be formatted as a JSON array"
# Setting changed by server but changed back client command line.
res = node.query("select 42::UInt64 as x format JSONEachRow", user='second_user', settings={"output_format_json_array_of_rows": "0"})
assert '[' not in res, "should not be formatted as a JSON array"
# User created at runtime.
node.query("create user u identified with plaintext_password by '' settings date_time_output_format='unix_timestamp'")
res = node.query("select toDateTime64('1970-01-02 00:00:00', 0)", user='u')
assert res == '86400\n'
node.query("drop user u")