Add test case for stat_instance_created_compute

Add 'no data, no hit' test case for test_search_action.py.

Change-Id: I147e64166c73fc55c925209f6734b27b9fe4a059
This commit is contained in:
hejunli 2022-09-06 11:23:17 +08:00
parent 94bc13a3e5
commit 9f18f2fde1

View File

@ -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()