ClickHouse/tests/integration/test_dictionaries_with_invalid_structure/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.5 KiB
Python
Raw Normal View History

2023-01-18 14:27:21 +00:00
import pytest
from helpers.client import QueryRuntimeException
from helpers.cluster import ClickHouseCluster
DICTIONARY_FILES = [
2023-01-19 14:02:57 +00:00
"configs/dictionaries/invalid_dict.xml",
2023-01-18 14:27:21 +00:00
"configs/dictionaries/valid_dict.xml",
]
cluster = ClickHouseCluster(__file__)
instance = cluster.add_instance("instance", dictionaries=DICTIONARY_FILES)
VALID_DICT_NAME = "valid_dict"
2023-01-19 15:48:09 +00:00
INVALID_DICT_NAME = "invalid_dict"
2023-01-18 14:27:21 +00:00
UNKNOWN_DATA_TYPE_EXCEPTION_STR = "DB::Exception: Unknown data type"
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
2023-01-19 15:48:09 +00:00
def test_select_from_system_dictionaries_with_invalid_dictionary(started_cluster):
2023-01-18 14:27:21 +00:00
query = instance.query
assert query("SELECT name FROM system.dictionaries;").splitlines() == [
VALID_DICT_NAME,
2023-01-19 15:48:09 +00:00
INVALID_DICT_NAME,
2023-01-18 14:27:21 +00:00
]
assert (
query(
f"select last_exception from system.dictionaries WHERE name='{VALID_DICT_NAME}';"
).strip()
== ""
)
assert (
UNKNOWN_DATA_TYPE_EXCEPTION_STR
in query(
2023-01-19 15:48:09 +00:00
f"select last_exception from system.dictionaries WHERE name='{INVALID_DICT_NAME}';"
2023-01-18 14:27:21 +00:00
).strip()
)
2023-01-19 15:48:09 +00:00
def test_dictGet_func_for_invalid_dictionary(started_cluster):
2023-01-18 14:27:21 +00:00
query = instance.query
with pytest.raises(QueryRuntimeException) as exc:
2023-01-19 15:48:09 +00:00
query(
f"SELECT dictGetString('{INVALID_DICT_NAME}', 'invalid_attr', toInt64(1));"
)
2023-01-18 14:27:21 +00:00
assert UNKNOWN_DATA_TYPE_EXCEPTION_STR in str(exc.value)