parent
f7784e641e
commit
c8538bdbb8
@ -258,6 +258,13 @@ class String(BaseType):
|
||||
self._basic_validation(value)
|
||||
if not value:
|
||||
return
|
||||
|
||||
if self.valid_values is not None:
|
||||
if value not in self.valid_values:
|
||||
raise configexc.ValidationError(
|
||||
value, "valid values: {}".format(', '.join(
|
||||
self.valid_values)))
|
||||
|
||||
if self.forbidden is not None and any(c in value
|
||||
for c in self.forbidden):
|
||||
raise configexc.ValidationError(value, "may not contain the chars "
|
||||
|
@ -305,6 +305,8 @@ class TestString:
|
||||
({'minlen': 2}, 'fo'),
|
||||
({'minlen': 2, 'maxlen': 3}, 'fo'),
|
||||
({'minlen': 2, 'maxlen': 3}, 'foo'),
|
||||
# valid_values
|
||||
({'valid_values': configtypes.ValidValues('fooo')}, 'fooo'),
|
||||
])
|
||||
def test_validate_valid(self, klass, kwargs, val):
|
||||
klass(**kwargs).validate(val)
|
||||
@ -319,6 +321,8 @@ class TestString:
|
||||
({'maxlen': 2}, 'fob'),
|
||||
({'minlen': 2, 'maxlen': 3}, 'f'),
|
||||
({'minlen': 2, 'maxlen': 3}, 'fooo'),
|
||||
# valid_values
|
||||
({'valid_values': configtypes.ValidValues('blah')}, 'fooo'),
|
||||
])
|
||||
def test_validate_invalid(self, klass, kwargs, val):
|
||||
with pytest.raises(configexc.ValidationError):
|
||||
|
Loading…
Reference in New Issue
Block a user