Add a test case of typical_stats to the test file

A test case for typical_stats: test_typical_stats_no_buckets,
which prints "no data, no buckets".

Change-Id: Idb763ecbcdf5322d712b5fbde3493b3e50a0e9dd
This commit is contained in:
hejunli 2022-08-24 10:57:01 +08:00
parent df17f84874
commit c7ecf527ea

View File

@ -477,6 +477,20 @@ class TestSearchAction(unittest.TestCase):
expected = {"code": 0, "msg": "no data, no data group"}
self.assertEqual(expected, result)
@mock.patch('venus.modules.search.es_template.search_logs')
@mock.patch('venus.modules.search.action.SearchCore.get_index_names')
@mock.patch('venus.common.utils.request_es')
def test_typical_stats_no_buckets(
self, mock_req_es, mock_get_index_names, mock_search_logs):
action = SearchCore()
mock_get_index_names.return_value = 'flog-2022.08.17,flog-2022.08.18'
mock_req_es.return_value = (200, '{"aggregations": {"data_group": '
'{}}}')
result = action.typical_stats({'log_level.keyword': 'test'}, '',
'1660722534', '1660808934')
expected = {"code": 0, "msg": "no data, no buckets"}
self.assertEqual(expected, result)
if __name__ == "__main__":
unittest.main()