Esempio n. 1
0
 def validate(self):
     '''Make sure exactly one of {source_port, dest_port} is set'''
     super(FlowClassifier, self).validate()
     if self.source_port is None and self.dest_port is None:
         raise errors.ValidationError(
             'One of source_port or dest_port must be set')
     elif self.source_port is not None and self.dest_port is not None:
         raise errors.ValidationError(
             'source_port and dest_port cannot be both set')
Esempio n. 2
0
 def validate(self, value):
     super(DhcpOptsDictField, self).validate(value)
     if not value:
         return
     for key, inner_val in value.items():
         if not dhcp.is_tag_valid(key):
             raise errors.ValidationError(
                 _('Key {} is not a vaild dhcp opt').format(key))
         if not isinstance(inner_val, six.string_types):
             raise errors.ValidationError(
                 _('Value {value} to key {key} is not a string').format(
                     key=key, value=inner_val))
Esempio n. 3
0
    def validate(self, value):
        if self.required and not value:
            raise errors.ValidationError(_('Field is required!'))

        if value is None:
            return

        for elem in value:
            if elem not in self._valid_values:
                raise errors.ValidationError(
                    _('{value} is not one of: [{valid_values}]').format(
                        value=value,
                        valid_values=', '.join(self._valid_values)))
Esempio n. 4
0
 def validate(self):
     """
     Validate the rule. That is, verify dscp_mark is set if type is
     dscp_marking, and that max_burst_kbps is set if type is bandwidth_limit
     """
     if self.type == RULE_TYPE_DSCP_MARKING:
         if self.dscp_mark is None:
             errors.ValidationError("dscp_mark is required if "
                                    "type is dscp_marking")
     elif self.type == RULE_TYPE_BANDWIDTH_LIMIT:
         if self.max_burst_kbps is None:
             errors.ValidationError("max_burst_kbps is required if "
                                    "type is bandwidth_limit")
Esempio n. 5
0
 def validate(self, value):
     super(IpProto, self).validate(value)
     if value is None:
         return
     if value < 0 or value > 255:
         raise errors.ValidationError(
             _('IP protocol value must to be in the'
               ' range [0,255] ({val} supplied )').format(val=value))
Esempio n. 6
0
 def validate(self):
     """
     Verify that the correct fields are filled for the correct type.
     e.g. for VLAN, segmentation_id is not None.
     """
     super(ChildPortSegmentation, self).validate()
     if self.segmentation_type == n_const.TYPE_VLAN:
         if self.segmentation_id is None:
             raise errors.ValidationError("segmentation_id required if "
                                          "segmentation_type is " +
                                          n_const.TYPE_VLAN)
Esempio n. 7
0
def test_regex_validation_custom_error():

    custom_error = errors.ValidationError("error")
    validator = validators.Regex('some', custom_error=custom_error)
    assert 'some' == validator.pattern

    validator.validate('some string')
    validator.validate('get some chips')

    expected_error = "error"

    with pytest.raises(errors.ValidationError) as exc_info:
        validator.validate('asdf')
    assert expected_error == str(exc_info.value)

    with pytest.raises(errors.ValidationError) as exc_info:
        validator.validate('trololo')
    assert expected_error == str(exc_info.value)
Esempio n. 8
0
 def validate(self, value):
     super(EnumField, self).validate(value)
     if value is not None and value not in self._valid_values:
         raise errors.ValidationError(
             _('{value} is not one of: [{valid_values}]').format(
                 value=value, valid_values=', '.join(self._valid_values)))
Esempio n. 9
0
 def __call__(self, value):
     if value not in self.options:
         raise errors.ValidationError('invalid option: %s' % value)
Esempio n. 10
0
def URIValidator(value):
    account = SIP_PREFIX_RE.sub('', value)
    try:
        SIPURI.parse('sip:%s' % account)
    except SIPCoreError:
        raise errors.ValidationError('invalid account: %s' % value)
Esempio n. 11
0
 def validate(self, value):
     if value != self.default_value:
         raise errors.ValidationError(
             '%s doesn\'t match the expected value %s' %
             (value, self.default_value))