From 1a6d7e5591811426eb35ac716c8a4e1a69c7b324 Mon Sep 17 00:00:00 2001 From: hejunli Date: Wed, 24 Aug 2022 10:59:48 +0800 Subject: [PATCH] Add a test case of typical_stats to the test file A test case for typical_stats: test_typical_stats_data, which prints "'code': 1, 'msg': 'OK', "data": ds". Change-Id: I32427699c2be2d149fc6759c79a487d6a2881686 --- venus/tests/unit/api/test_search_action.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/venus/tests/unit/api/test_search_action.py b/venus/tests/unit/api/test_search_action.py index 726965b..e4f93a1 100644 --- a/venus/tests/unit/api/test_search_action.py +++ b/venus/tests/unit/api/test_search_action.py @@ -491,6 +491,23 @@ class TestSearchAction(unittest.TestCase): expected = {"code": 0, "msg": "no data, no buckets"} self.assertEqual(expected, result) + @mock.patch('venus.modules.search.es_template.search_params') + @mock.patch('venus.modules.search.action.SearchCore.get_index_names') + @mock.patch('venus.common.utils.request_es') + def test_typical_stats_data( + self, mock_req_es, mock_get_index_names, mock_search_logs): + action = SearchCore() + mock_req_es.return_value = (200, '{"aggregations": {"data_group":' + ' {"buckets": [{"key": "value"}' + ' ]}}}') + mock_get_index_names.return_value = 'flog-2022.08.17,flog-2022.08.18' + result = action.typical_stats({'log_level.keyword': 'test'}, '', + '1660722534', '1660808934') + expected = {'code': 1, 'msg': 'OK', + "data": {'stats': [], 'interval_cn': '30分钟', + 'interval_en': '30minutes'}} + self.assertEqual(expected, result) + if __name__ == "__main__": unittest.main()