From 730483677513e54fc2838e94e92015cccd8e5c56 Mon Sep 17 00:00:00 2001 From: hejunli Date: Mon, 29 Aug 2022 11:16:48 +0800 Subject: [PATCH] Add a use case for the test unit A test case for typical_logs: test_typical_logs_no_aggregations_data, which prints "no aggregations". Change-Id: I4737219de4e239b8426d3072461a49cc14338413 --- venus/tests/unit/api/test_search_action.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/venus/tests/unit/api/test_search_action.py b/venus/tests/unit/api/test_search_action.py index 65f3ba5..2d6b67e 100644 --- a/venus/tests/unit/api/test_search_action.py +++ b/venus/tests/unit/api/test_search_action.py @@ -541,6 +541,27 @@ class TestSearchAction(unittest.TestCase): '1660808934') 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_logs_no_aggregations( + self, mock_req_es, mock_get_index_names, mock_search_params): + mock_get_index_names.return_value = 'flog-2022.08.17,flog-2022.08.18' + mock_req_es.return_value = (200, '{}') + action = SearchCore() + expected = {"code": 0, "msg": "no data, no aggregations"} + result = action.typical_logs('error_stats', '1660722534', '1660808934') + self.assertEqual(expected, result) + result = action.typical_logs('rabbitmq_error_stats', '1660722534', + '1660808934') + self.assertEqual(expected, result) + result = action.typical_logs('mysql_error_stats', '1660722534', + '1660808934') + self.assertEqual(expected, result) + result = action.typical_logs('novalidhost_error_stats', '1660722534', + '1660808934') + self.assertEqual(expected, result) + if __name__ == "__main__": unittest.main()