From 025a0b2b2900a18f187147dcf7e4f808182b1b81 Mon Sep 17 00:00:00 2001 From: hejunli Date: Mon, 29 Aug 2022 11:11:35 +0800 Subject: [PATCH] A test case for typical_logs You can test internal error status by using this test. Change-Id: Iedf0f68087088d0205bf69b6884ee761b3541ebc --- 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 28f232b..65f3ba5 100644 --- a/venus/tests/unit/api/test_search_action.py +++ b/venus/tests/unit/api/test_search_action.py @@ -520,6 +520,27 @@ class TestSearchAction(unittest.TestCase): result = action.typical_logs('novalidhost_error_stats', '2', '1') 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_internal_error( + 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 = (400, {}) + action = SearchCore() + expected = {"code": -1, "msg": "internal error, bad request"} + 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()