DomainnameOption now works with default value
This commit is contained in:
parent
6de65859b4
commit
6ffd71a43e
@ -7,7 +7,8 @@ from tiramisu.option import DomainnameOption, OptionDescription
|
||||
|
||||
def test_domainname():
|
||||
d = DomainnameOption('d', '')
|
||||
od = OptionDescription('a', '', [d])
|
||||
e = DomainnameOption('e', '', "toto.com")
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
c.d = 'toto.com'
|
||||
raises(ValueError, "c.d = 'toto'")
|
||||
@ -21,7 +22,8 @@ def test_domainname():
|
||||
|
||||
def test_domainname_netbios():
|
||||
d = DomainnameOption('d', '', type_='netbios')
|
||||
od = OptionDescription('a', '', [d])
|
||||
e = DomainnameOption('e', '', "toto", type_='netbios')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.d = 'toto.com'")
|
||||
c.d = 'toto'
|
||||
@ -30,7 +32,8 @@ def test_domainname_netbios():
|
||||
|
||||
def test_domainname_hostname():
|
||||
d = DomainnameOption('d', '', type_='hostname')
|
||||
od = OptionDescription('a', '', [d])
|
||||
e = DomainnameOption('e', '', "toto", type_='hostname')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
raises(ValueError, "c.d = 'toto.com'")
|
||||
c.d = 'toto'
|
||||
|
@ -528,7 +528,6 @@ class NetmaskOption(Option):
|
||||
class DomainnameOption(Option):
|
||||
__slots__ = ('_opt_type', '_type', '_allow_ip')
|
||||
_opt_type = 'domainname'
|
||||
#allow_ip
|
||||
|
||||
def __init__(self, name, doc, default=None, default_multi=None,
|
||||
requires=None, multi=False, callback=None,
|
||||
@ -538,6 +537,12 @@ class DomainnameOption(Option):
|
||||
#hostname: to identify the device
|
||||
#domainname:
|
||||
#fqdn: with tld, not supported yet
|
||||
if type_ not in ['netbios', 'hostname', 'domainname']:
|
||||
raise ValueError(_('unknown type_ {0} for hostname').format(type_))
|
||||
self._type = type_
|
||||
if allow_ip not in [True, False]:
|
||||
raise ValueError(_('allow_ip must be a boolean'))
|
||||
self._allow_ip = allow_ip
|
||||
super(DomainnameOption, self).__init__(name, doc, default=default,
|
||||
default_multi=default_multi,
|
||||
callback=callback,
|
||||
@ -547,10 +552,6 @@ class DomainnameOption(Option):
|
||||
validator=validator,
|
||||
validator_args=validator_args,
|
||||
properties=properties)
|
||||
if type_ not in ['netbios', 'hostname', 'domainname']:
|
||||
raise ValueError(_('unknown type_ {0} for hostname').format(type_))
|
||||
self._type = type_
|
||||
self._allow_ip = allow_ip
|
||||
|
||||
def _validate(self, value):
|
||||
if self._allow_ip is True:
|
||||
|
Loading…
Reference in New Issue
Block a user