File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
stac_fastapi/tests/extensions Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+ from stac_fastapi .core .extensions .filter import cql2_like_to_es
4
+
5
+
6
+ @pytest .mark .parametrize (
7
+ "cql2_value, expected_es_value" ,
8
+ (
9
+ # no-op
10
+ ("" , "" ),
11
+ # backslash
12
+ ("\\ \\ " , "\\ " ),
13
+ # percent
14
+ ("%" , "*" ),
15
+ (r"\%" , "%" ),
16
+ (r"\\%" , r"\*" ),
17
+ (r"\\\%" , r"\%" ),
18
+ # underscore
19
+ ("_" , "?" ),
20
+ (r"\_" , "_" ),
21
+ (r"\\_" , r"\?" ),
22
+ (r"\\\_" , r"\_" ),
23
+ ),
24
+ )
25
+ def test_cql2_like_to_es_success (cql2_value : str , expected_es_value : str ) -> None :
26
+ """Verify CQL2 LIKE query strings are converted correctly."""
27
+
28
+ assert cql2_like_to_es (cql2_value ) == expected_es_value
29
+
30
+
31
+ @pytest .mark .parametrize (
32
+ "cql2_value" ,
33
+ (
34
+ pytest .param ("\\ " , id = "trailing backslash escape" ),
35
+ pytest .param ("\\ 1" , id = "invalid escape sequence" ),
36
+ ),
37
+ )
38
+ def test_cql2_like_to_es_invalid (cql2_value : str ) -> None :
39
+ """Verify that incomplete or invalid escape sequences are rejected.
40
+
41
+ CQL2 currently doesn't appear to define how to handle invalid escape sequences.
42
+ This test assumes that undefined behavior is caught.
43
+ """
44
+
45
+ with pytest .raises (ValueError ):
46
+ cql2_like_to_es (cql2_value )
You can’t perform that action at this time.
0 commit comments