|
@@ -15,6 +15,7 @@ from sentry.api.event_search import (
|
|
SearchKey,
|
|
SearchKey,
|
|
SearchValue,
|
|
SearchValue,
|
|
parse_search_query,
|
|
parse_search_query,
|
|
|
|
+ translate_wildcard_as_clickhouse_pattern,
|
|
)
|
|
)
|
|
from sentry.constants import MODULE_ROOT
|
|
from sentry.constants import MODULE_ROOT
|
|
from sentry.exceptions import InvalidSearchQuery
|
|
from sentry.exceptions import InvalidSearchQuery
|
|
@@ -756,3 +757,31 @@ def test_search_value_classify_and_format_wildcard(value, expected_kind, expecte
|
|
search_value = SearchValue(value)
|
|
search_value = SearchValue(value)
|
|
kind, wildcard = search_value.classify_and_format_wildcard()
|
|
kind, wildcard = search_value.classify_and_format_wildcard()
|
|
assert (kind, wildcard) == (expected_kind, expected_value)
|
|
assert (kind, wildcard) == (expected_kind, expected_value)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@pytest.mark.parametrize(
|
|
|
|
+ ["pattern", "clickhouse"],
|
|
|
|
+ [
|
|
|
|
+ pytest.param("simple", "simple", id="simple"),
|
|
|
|
+ pytest.param("wild * card", "wild % card", id="wildcard"),
|
|
|
|
+ pytest.param("under_score", "under\\_score", id="underscore"),
|
|
|
|
+ pytest.param("per%centage", "per\\%centage", id="percentage"),
|
|
|
|
+ pytest.param("ast\\*erisk", "ast*erisk", id="asterisk"),
|
|
|
|
+ pytest.param("c*o_m%p\\*lex", "c%o\\_m\\%p*lex", id="complex"),
|
|
|
|
+ ],
|
|
|
|
+)
|
|
|
|
+def test_translate_wildcard_as_clickhouse_pattern(pattern, clickhouse):
|
|
|
|
+ assert translate_wildcard_as_clickhouse_pattern(pattern) == clickhouse
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@pytest.mark.parametrize(
|
|
|
|
+ ["pattern"],
|
|
|
|
+ [
|
|
|
|
+ pytest.param("\\."),
|
|
|
|
+ pytest.param("\\%"),
|
|
|
|
+ pytest.param("\\_"),
|
|
|
|
+ ],
|
|
|
|
+)
|
|
|
|
+def test_invalid_translate_wildcard_as_clickhouse_pattern(pattern):
|
|
|
|
+ with pytest.raises(InvalidSearchQuery):
|
|
|
|
+ assert translate_wildcard_as_clickhouse_pattern(pattern)
|