Skip to content

Commit 33d0033

Browse files
Define new test case in test_parsers.py
Defined `test_search_query_with_field_aliases` method in `TestDirectoryQueryParser` class for testing directory query parser with search query comprising field aliases.
1 parent 10bfd9c commit 33d0033

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/test_query/test_handlers/test_parsers.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ class TestDirectoryQueryParser:
157157
"* FROM ABSOLUTE '.' WHERE atime >= '2024-02-20'",
158158
]
159159

160+
search_query_with_field_aliases_test_params = [
161+
"filename, filepath FROM ABSOLUTE .",
162+
"filepath, ctime,atime FROM . WHERE atime <= '2023-01-01' AND ctime >= '2006-02-20'",
163+
"filename, mtime FROM RELATIVE . WHERE mtime BETWEEN ('2021-03-12', '2021-04-12')",
164+
]
165+
160166
# The following list comprises results for the file search query test comprising sub-lists,
161167
# each with a length of 2. The first element of each sub-list signifies whether the path is
162168
# absolute (True) or relative (False) whereas the second element is a list comprising names
@@ -169,6 +175,12 @@ class TestDirectoryQueryParser:
169175
[True, list(constants.DIR_FIELDS)],
170176
]
171177

178+
search_query_with_field_aliases_test_results = [
179+
[True, ["name", "path"], ["filename", "filepath"]],
180+
[False, ["path", "create_time", "access_time"], ["filepath", "ctime", "atime"]],
181+
[False, ["name", "modify_time"], ["filename", "mtime"]],
182+
]
183+
172184
@pytest.mark.parametrize(
173185
("subquery", "results"),
174186
zip(search_query_test_params, search_query_test_results),
@@ -183,3 +195,23 @@ def test_search_query(self, subquery, results) -> None:
183195
fields: list[str] = results[1]
184196

185197
assert [field.field for field in search_query.fields] == fields
198+
199+
@pytest.mark.parametrize(
200+
("subquery", "results"),
201+
zip(
202+
search_query_with_field_aliases_test_params,
203+
search_query_with_field_aliases_test_results,
204+
),
205+
)
206+
def test_search_query_with_field_aliases(self, subquery, results) -> None:
207+
"""
208+
Tests the file query parser with search queries comprising field aliases.
209+
"""
210+
211+
query: list[str] = tools.parse_query(subquery)
212+
parser = FileQueryParser(query, "search")
213+
214+
search_query: SearchQuery = examine_search_query(parser, results)
215+
fields: list[str] = results[1]
216+
217+
assert [field.field for field in search_query.fields] == fields

0 commit comments

Comments
 (0)