From 7c0facacd52245fd2c28a64b65a32dd04404880e Mon Sep 17 00:00:00 2001 From: rahul4732saini Date: Mon, 15 Jul 2024 20:35:06 +0530 Subject: [PATCH] Update test_parsers.py Defined `test_search_query_with_field_aliases` method in `TestFileDataQueryParser` class for testing file query parser with delete queries. Also defined attributes comprising parameters and results for the same. --- .../test_query/test_handlers/test_parsers.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test_query/test_handlers/test_parsers.py b/tests/test_query/test_handlers/test_parsers.py index f30d42d..18077c5 100644 --- a/tests/test_query/test_handlers/test_parsers.py +++ b/tests/test_query/test_handlers/test_parsers.py @@ -197,6 +197,12 @@ class TestFileDataQueryParser: "* FROM '.' WHERE lineno BETWEEN (0, 100)", ] + search_query_with_field_aliases_test_params = [ + "filename, data FROM .", + "filename, type, line FROM RELATIVE . WHERE type = '.py' AND line > 10", + "filename, filepath FROM ABSOLUTE . WHERE 'test' in data", + ] + # The following are test results for the search query tests comprising sub-lists, each with # a variable length where the first element of each of them signifies whether the path is # absolute (True) or relative (False) whereas the last element in it is a list comprising @@ -210,6 +216,12 @@ class TestFileDataQueryParser: [False, list(constants.DATA_FIELDS)], ] + search_query_with_field_aliases_test_results = [ + [False, ["name", "dataline"], ["filename", "data"]], + [False, ["name", "filetype", "dataline"], ["filename", "type", "line"]], + [True, ["name", "path"], ["filename", "filepath"]], + ] + @pytest.mark.parametrize( ("subquery", "results"), zip(search_query_test_params, search_query_test_results), @@ -227,6 +239,26 @@ def test_search_query(self, subquery: str, results: list[Any]) -> None: assert [field.field for field in search_query.fields] == fields + @pytest.mark.parametrize( + ("subquery", "results"), + zip( + search_query_with_field_aliases_test_params, + search_query_with_field_aliases_test_results, + ), + ) + def test_search_query(self, subquery: str, results: list[Any]) -> None: + """ + Tests the file data query parser with search queries comprising field aliases. + """ + + query: list[str] = tools.parse_query(subquery) + parser = FileDataQueryParser(query) + + search_query: SearchQuery = examine_search_query(parser, results) + fields: list[str] = results[1] + + assert [field.field for field in search_query.fields] == fields + class TestDirectoryQueryParser: """Tests the DirectoryQueryParser class"""