From 9f18f2fde135a36027279e3adff8717bf7605255 Mon Sep 17 00:00:00 2001 From: hejunli Date: Tue, 6 Sep 2022 11:23:17 +0800 Subject: [PATCH] Add test case for stat_instance_created_compute Add 'no data, no hit' test case for test_search_action.py. Change-Id: I147e64166c73fc55c925209f6734b27b9fe4a059 --- venus/tests/unit/api/test_search_action.py | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/venus/tests/unit/api/test_search_action.py b/venus/tests/unit/api/test_search_action.py index 53fc783..c17af0e 100644 --- a/venus/tests/unit/api/test_search_action.py +++ b/venus/tests/unit/api/test_search_action.py @@ -643,6 +643,32 @@ class TestSearchAction(unittest.TestCase): expected = (None, 'internal error, bad request') 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_stat_instance_created_compute_no_hit( + 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' + action = SearchCore() + mock_req_es.return_value = (200, '{}') + result = action.stat_instance_created_compute('', '', '', '1660722534', + '1660808934') + expected = ([], "no data, no hit") + 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_stat_instance_created_compute_hit( + 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' + action = SearchCore() + mock_req_es.return_value = (200, '{"hits": {}}') + result = action.stat_instance_created_compute('', '', '', '1660722534', + '1660808934') + expected = ([], "no data, no hit") + self.assertEqual(expected, result) + if __name__ == "__main__": unittest.main()