def test_get_path_lists_search(self): # search parameter is a dictionary with values value and negation result = get_path_lists(search={'value': 'audit-keys', 'negation': 0}) self.assertEqual(len(result['items']), 1) result = get_path_lists(search={'value': 'AAABBBCCC', 'negation': 0}) self.assertEqual(len(result['items']), 0)
def test_get_path_lists_sort(self): # sort parameter is a dictionary with values fields and order result_a = get_path_lists(sort={'fields': ['path'], 'order': 'asc'}) result_b = get_path_lists(sort={'fields': ['path'], 'order': 'desc'}) self.assertNotEqual(result_a, result_b) result_a = get_path_lists(sort={'fields': ['name'], 'order': 'asc'}) result_b = get_path_lists(sort={'fields': ['name'], 'order': 'desc'}) self.assertNotEqual(result_a, result_b)
def test_get_path_lists_limit(self): with self.assertRaises(WazuhException) as cm: get_path_lists(limit=0) self.assertEqual(cm.exception.code, 1406) result = get_path_lists(limit=1) self.assertEqual(len(result['items']), 1) result = get_path_lists(limit=3) self.assertEqual(len(result['items']), 3)
def test_get_path_lists_sort(iterate_mock): """Test `get_path_lists` functionality when using the `sort` parameter.""" result_a = get_path_lists(filename=NAME_FILES, sort_by=['filename'], sort_ascending=True) result_b = get_path_lists(filename=NAME_FILES, sort_by=['filename'], sort_ascending=False) assert isinstance(result_a, AffectedItemsWazuhResult) assert isinstance(result_b, AffectedItemsWazuhResult) assert result_a.affected_items != result_b.affected_items assert result_a.affected_items == RESULT_GET_PATH_LIST_FILE_1 + RESULT_GET_PATH_LIST_FILE_2 assert result_b.affected_items == RESULT_GET_PATH_LIST_FILE_2 + RESULT_GET_PATH_LIST_FILE_1
def test_get_path_lists_search(iterate_mock, search_text, complementary_search, search_in_fields, paths, expected_result): """Test `get_path_lists` functionality when using the `search` parameter. Parameters ---------- search_text : str The text to search. complementary_search : bool If True, only results NOT containing `search_text` will be returned. If False, only results that contains `search_text` will be returned. search_in_fields : str Name of the field to search in for the `search_text`. paths : list of str A list of CDB files to read, with their relative path. expected_result : list of dict The content expected to be returned by `get_lists` when using the specified search parameters. """ common.reset_context_cache() result = get_path_lists(filename=paths, search_text=search_text, complementary_search=complementary_search, search_in_fields=search_in_fields, sort_by=['filename']) assert isinstance(result, AffectedItemsWazuhResult) assert result.total_affected_items == len(expected_result) assert result.affected_items == expected_result
def test_get_path_lists(iterate_mock): """Test `get_path_lists` functionality without any other parameter aside from `path`. `get_path_lists` works different than `get_lists` as it will read every CDB file from the default path (mocked to `DATA_PATH`) and will remove from the result any file that is not in the `path` parameter provided. """ common.reset_context_cache() result = get_path_lists(filename=[NAME_FILE_1]) assert isinstance(result, AffectedItemsWazuhResult) assert result.total_affected_items == len(RESULT_GET_PATH_LIST_FILE_1) assert result.affected_items == RESULT_GET_PATH_LIST_FILE_1
def test_get_path_lists_offset(iterate_mock, offset): """Test `get__path_lists` functionality when using the `offset` parameter. Parameters ---------- offset : int Indicates the first item to return. """ common.reset_context_cache() result = get_path_lists(filename=NAME_FILES, offset=offset, sort_by=['filename']) assert isinstance(result, AffectedItemsWazuhResult) assert result.total_affected_items == TOTAL_LISTS assert result.affected_items == RESULTS_GET_PATH_LIST[offset:]