def pre_add(self, item: "ValidatorInlineView") -> None: if item.alert.validators and item.alert.validators[0].id != item.id: raise SupersetException( "Error: Alerts currently only support 1 validator per alert.") item.validator_type = item.validator_type.lower() check_validator(item.validator_type, item.config)
def pre_add(self, item: "AlertModelView") -> None: item.recipients = get_email_address_str(item.recipients) if not croniter.is_valid(item.crontab): raise SupersetException("Invalid crontab format") item.validator_type = item.validator_type.lower() check_validator(item.validator_type, item.validator_config)
def pre_update(self, item: "AlertModelView") -> None: item.validator_type = item.validator_type.lower() check_validator(item.validator_type, item.validator_config)
def test_check_validator(): # Test with invalid operator type with pytest.raises(SupersetException): check_validator("greater than", "{}") # Test with empty config with pytest.raises(SupersetException): check_validator("operator", "{}") # Test with invalid operator with pytest.raises(SupersetException): check_validator("operator", '{"op": "is", "threshold":50.0}') # Test with invalid operator with pytest.raises(SupersetException): check_validator("operator", '{"op": "is", "threshold":50.0}') # Test with invalid threshold with pytest.raises(SupersetException): check_validator("operator", '{"op": "is", "threshold":"hello"}') # Test with float threshold and no errors assert check_validator("operator", '{"op": ">=", "threshold": 50.0}') is None # Test with int threshold and no errors assert check_validator("operator", '{"op": "==", "threshold": 50}') is None
def test_check_validator_no_error(description, validator_type, config): logger.info(description) assert check_validator(validator_type, config) is None
def test_check_validator_error(description, validator_type, config): logger.info(description) with pytest.raises(SupersetException): check_validator(validator_type, config)
def pre_update(self, item: "ValidatorInlineView") -> None: item.validator_type = item.validator_type.lower() check_validator(item.validator_type, item.config)