def test_alert_query_str_with_sort_key_gives_correct_json_representation( event_filter_group): alert_query = AlertQuery(_TENANT_ID, event_filter_group) alert_query.sort_key = "some_field_to_sort_by" json_query_str = JSON_QUERY_BASE.format(_TENANT_ID, "AND", event_filter_group, 0, 10000, "desc", "some_field_to_sort_by") assert str(alert_query) == json_query_str
def _construct_query(state, begin, end, advanced_query, or_query): if advanced_query: state.search_filters = advanced_query else: if begin or end: state.search_filters.append( create_time_range_filter(f.DateObserved, begin, end)) if or_query: state.search_filters = convert_to_or_query(state.search_filters) query = AlertQuery(*state.search_filters) query.page_size = ALERT_PAGE_SIZE query.sort_direction = "asc" query.sort_key = "CreatedAt" return query
def test_alerts_client_get_all_alert_details_sorts_results_descending_when_specified( self, mock_alerts_service_with_pages, mock_alert_rules_service, mock_details, sort_key, ): mock_alerts_service = mock_alerts_service_with_pages(ascending=False) mock_alerts_service.get_details = mock_details alert_client = AlertsClient(mock_alerts_service, mock_alert_rules_service) query = AlertQuery() query.sort_direction = "desc" query.sort_key = sort_key results = list(alert_client.get_all_alert_details(query)) assert results == [ ALERT_F, ALERT_E, ALERT_D, ALERT_C, ALERT_B, ALERT_A ]
def test_alerts_client_get_all_alert_details_sorts_results_according_to_query_sort_key( self, mock_alerts_service_with_pages, mock_alert_rules_service, mock_details, sort_key, ): mock_alerts_service = mock_alerts_service_with_pages(ascending=True) mock_alerts_service.get_details = mock_details alert_client = AlertsClient(mock_alerts_service, mock_alert_rules_service) query = AlertQuery() query.sort_direction = "asc" query.sort_key = sort_key results = list(alert_client.get_all_alert_details(query)) assert results == [ ALERT_A, ALERT_B, ALERT_C, ALERT_D, ALERT_E, ALERT_F ]