def test_append_alert_condition_data(self): # We pull it from schema and make a ConditionData # instance with the below dict. condition_data_type = schema.get_type('ConditionData') condition_data = condition_data_type.create_container({ 'at_least_count': 3, 'at_least_filter_id': None, 'severity': 5.6, 'direction': None, }) with_direction = condition_data_type.create_container( {'direction': 'changed'}) empty_data = condition_data_type.create_container({}) # should return None if there is no data to append self.assertIsNone( append_alert_condition_data('Filter count at least', empty_data)) # should append correct data self.assertEqual( append_alert_condition_data('Filter count at least', condition_data), {'count': '3'}, ) self.assertEqual( append_alert_condition_data('Severity at least', condition_data), {'severity': '5.6'}, ) # direction is None, so nothing is appended self.assertIsNone( append_alert_condition_data('Severity changed', condition_data)) self.assertEqual( append_alert_condition_data('Severity changed', with_direction), {'direction': 'changed'}, )
def mutate(root, info, input_object): gmp = get_gmp(info) if input_object.event_data is not None: event_data = append_alert_event_data( input_object.event, input_object.event_data ) else: event_data = None if input_object.method_data is not None: method_data = append_alert_method_data( input_object.method, input_object.method_data, report_formats=input_object.report_formats, ) else: method_data = None if input_object.condition_data is not None: condition_data = append_alert_condition_data( input_object.condition, input_object.condition_data ) else: condition_data = None if input_object.filter_id is not None: filter_id = str(input_object.filter_id) else: filter_id = None gmp.modify_alert( alert_id=str(input_object.alert_id), name=input_object.name, condition=get_alert_condition_from_string(input_object.condition), event=get_alert_event_from_string(input_object.event), method=get_alert_method_from_string(input_object.method), comment=input_object.comment, method_data=method_data, condition_data=condition_data, event_data=event_data, filter_id=filter_id, ) return ModifyAlert(ok=True)
def mutate(root, info, input_object): gmp = get_gmp(info) if input_object.event_data is not None: event_data = append_alert_event_data( input_object.event, input_object.event_data ) else: event_data = None if input_object.method_data is not None: method_data = append_alert_method_data( input_object.method, input_object.method_data, report_formats=input_object.report_formats, ) else: method_data = None if input_object.condition_data is not None: condition_data = append_alert_condition_data( input_object.condition, input_object.condition_data ) else: condition_data = None if input_object.filter_id is not None: filter_id = str(input_object.filter_id) else: filter_id = None resp = gmp.create_alert( input_object.name, get_alert_condition_from_string(input_object.condition), get_alert_event_from_string(input_object.event), get_alert_method_from_string(input_object.method), comment=input_object.comment, method_data=method_data, condition_data=condition_data, event_data=event_data, filter_id=filter_id, ) return CreateAlert(alert_id=resp.get('id'))