add some tests
This commit is contained in:
@@ -296,12 +296,9 @@ class SubConfig(object):
|
||||
:return: find list or an exception if nothing has been found
|
||||
"""
|
||||
def _filter_by_name():
|
||||
try:
|
||||
if byname is None or path == byname or \
|
||||
path.endswith('.' + byname):
|
||||
return True
|
||||
except IndexError:
|
||||
pass
|
||||
if byname is None or path == byname or \
|
||||
path.endswith('.' + byname):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _filter_by_value():
|
||||
@@ -452,22 +449,16 @@ class SubConfig(object):
|
||||
|
||||
def _make_sub_dict(self, opt, path, pathsvalues, _currpath, flatten):
|
||||
if isinstance(opt, OptionDescription):
|
||||
try:
|
||||
pathsvalues += getattr(self, path).make_dict(flatten,
|
||||
_currpath +
|
||||
path.split('.'))
|
||||
except PropertiesOptionError:
|
||||
pass # this just a hidden or disabled option
|
||||
pathsvalues += getattr(self, path).make_dict(flatten,
|
||||
_currpath +
|
||||
path.split('.'))
|
||||
else:
|
||||
try:
|
||||
value = self._getattr(opt._name)
|
||||
if flatten:
|
||||
name = opt._name
|
||||
else:
|
||||
name = '.'.join(_currpath + [opt._name])
|
||||
pathsvalues.append((name, value))
|
||||
except PropertiesOptionError:
|
||||
pass # this just a hidden or disabled option
|
||||
value = self._getattr(opt._name)
|
||||
if flatten:
|
||||
name = opt._name
|
||||
else:
|
||||
name = '.'.join(_currpath + [opt._name])
|
||||
pathsvalues.append((name, value))
|
||||
|
||||
def cfgimpl_get_path(self):
|
||||
descr = self.cfgimpl_get_description()
|
||||
|
@@ -662,7 +662,7 @@ class ChoiceOption(Option):
|
||||
return self._open_values
|
||||
|
||||
def _validate(self, value):
|
||||
if not self._open_values and not value in self._values:
|
||||
if not self.impl_is_openvalues() and not value in self.impl_get_values():
|
||||
raise ValueError(_('value {0} is not permitted, '
|
||||
'only {1} is allowed'
|
||||
'').format(value, self._values))
|
||||
@@ -782,9 +782,13 @@ class IPOption(Option):
|
||||
def _validate(self, value):
|
||||
# sometimes an ip term starts with a zero
|
||||
# but this does not fit in some case, for example bind does not like it
|
||||
for val in value.split('.'):
|
||||
if val.startswith("0") and len(val) > 1:
|
||||
raise ValueError(_('invalid IP'))
|
||||
try:
|
||||
for val in value.split('.'):
|
||||
if val.startswith("0") and len(val) > 1:
|
||||
raise ValueError(_('invalid IP'))
|
||||
except AttributeError:
|
||||
#if integer for example
|
||||
raise ValueError(_('invalid IP'))
|
||||
# 'standard' validation
|
||||
try:
|
||||
IP('{0}/32'.format(value))
|
||||
@@ -856,18 +860,22 @@ class PortOption(Option):
|
||||
if self._allow_range and ":" in str(value):
|
||||
value = str(value).split(':')
|
||||
if len(value) != 2:
|
||||
raise ValueError('invalid part, range must have two values '
|
||||
'only')
|
||||
raise ValueError(_('invalid part, range must have two values '
|
||||
'only'))
|
||||
if not value[0] < value[1]:
|
||||
raise ValueError('invalid port, first port in range must be'
|
||||
' smaller than the second one')
|
||||
raise ValueError(_('invalid port, first port in range must be'
|
||||
' smaller than the second one'))
|
||||
else:
|
||||
value = [value]
|
||||
|
||||
for val in value:
|
||||
if not self._min_value <= int(val) <= self._max_value:
|
||||
raise ValueError('invalid port, must be an between {0} and {1}'
|
||||
''.format(self._min_value, self._max_value))
|
||||
try:
|
||||
if not self._min_value <= int(val) <= self._max_value:
|
||||
raise ValueError(_('invalid port, must be an between {0} '
|
||||
'and {1}').format(self._min_value,
|
||||
self._max_value))
|
||||
except ValueError:
|
||||
raise ValueError(_('invalid port'))
|
||||
|
||||
|
||||
class NetworkOption(Option):
|
||||
|
@@ -66,6 +66,8 @@ class Values(object):
|
||||
meta = self._getcontext().cfgimpl_get_meta()
|
||||
if meta is not None:
|
||||
value = meta.cfgimpl_get_values()[opt]
|
||||
if isinstance(value, Multi):
|
||||
value = list(value)
|
||||
else:
|
||||
value = opt.impl_getdefault()
|
||||
if opt.impl_is_multi():
|
||||
|
Reference in New Issue
Block a user