def test_get_lists_search(self): # search parameter is a dictionary with values value and negation result = get_lists(search={'value': 'audit-keys', 'negation': 0}) self.assertEqual(len(result['items']), 1) result = get_lists(search={'value': 'AAABBBCCC', 'negation': 0}) self.assertEqual(len(result['items']), 0)
def test_get_lists_path(self): result = get_lists(path='etc/lists/audit-keys') self.assertEqual(len(result['items']), 1) with self.assertRaises(WazuhException) as cm: get_lists(path='wrong_path') self.assertEqual(cm.exception.code, 1801)
def test_get_lists_limit(self): with self.assertRaises(WazuhException) as cm: get_lists(limit=0) self.assertEqual(cm.exception.code, 1406) result = get_lists(limit=1) self.assertEqual(result['totalItems'], 1) result = get_lists(limit=3) self.assertEqual(result['totalItems'], 3)
def test_get_lists_sort(): """Test `get_lists` functionality when using the `sort` parameter.""" result_a = get_lists(filename=NAME_FILES, sort_by=['filename'], sort_ascending=True) result_b = get_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_LIST_FILE_1 + RESULT_GET_LIST_FILE_2 assert result_b.affected_items == RESULT_GET_LIST_FILE_2 + RESULT_GET_LIST_FILE_1
def test_get_lists_search(search_text, complementary_search, search_in_fields, paths, expected_result): """Test `get_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. """ result = get_lists(filename=paths, search_text=search_text, complementary_search=complementary_search, search_in_fields=search_in_fields) assert isinstance(result, AffectedItemsWazuhResult) assert result.total_affected_items == len(expected_result) assert result.affected_items == expected_result
def test_get_lists_offset(offset): """Test `get_lists` functionality when using the `offset` parameter. Parameters ---------- offset : int Indicates the first item to return. """ result = get_lists(filename=NAME_FILES, offset=offset) assert isinstance(result, AffectedItemsWazuhResult) assert result.total_affected_items == TOTAL_LISTS assert result.affected_items == RESULTS_GET_LIST[offset:]
def test_get_lists_limit(limit): """Test `get_lists` functionality when using the `limit` parameter. Parameters ---------- limit : int Maximum number of items to be returned by `get_lists` """ result = get_lists(filename=NAME_FILES, limit=limit) assert limit > 0 assert isinstance(result, AffectedItemsWazuhResult) assert result.total_affected_items == TOTAL_LISTS assert result.affected_items == RESULTS_GET_LIST[:limit]
def test_get_lists(paths, expected_result): """Test basic `get_list` functionality. This will obtain the content of some CDB lists using `get_list'' without any other parameter aside from `path`. Parameters ---------- paths : list of str A list of CDB files to read, with their relative path. expected_result : list of dict The content of the CDB file or files read """ result = get_lists(filename=paths) assert isinstance(result, AffectedItemsWazuhResult) assert result.total_affected_items == len(paths) assert result.affected_items == expected_result
def test_get_lists_sort(self): # sort parameter is a dictionary with values fields and order result_a = get_lists(sort={'fields': ['path'], 'order': 'asc'}) result_b = get_lists(sort={'fields': ['path'], 'order': 'desc'}) self.assertNotEqual(result_a, result_b)
def test_get_lists_offset(self): result_a = get_lists(offset=0) result_b = get_lists(offset=1) self.assertNotEqual(result_a, result_b)
def test_get_lists(self): result = get_lists() self.assertIsInstance(result, dict) self.assertIsInstance(result['totalItems'], int) self.assertIsInstance(result['items'], list)