Supplement test case for typical_logs

Add 'no data, no data group' test case of typical_logs
to test_search_action.py.

Change-Id: Ib9c7821aacf96959a6b818b015a8d6d9eb7c5bfc
This commit is contained in:
hejunli 2022-08-29 11:20:12 +08:00
parent 7304836775
commit 3e898ee5b3

View File

@ -562,6 +562,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_data_group(
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, '{"aggregations": {}}')
action = SearchCore()
expected = {"code": 0, "msg": "no data, no data group"}
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()