2013-05-31 23:29:20 +02:00
|
|
|
# coding: utf-8
|
|
|
|
import autopath
|
2013-06-29 18:41:14 +02:00
|
|
|
from copy import copy
|
2013-05-31 23:29:20 +02:00
|
|
|
from tiramisu import setting
|
|
|
|
setting.expires_time = 1
|
2013-07-03 15:04:15 +02:00
|
|
|
from tiramisu.option import IPOption, OptionDescription, BoolOption, IntOption, StrOption
|
2013-05-31 23:29:20 +02:00
|
|
|
from tiramisu.config import Config
|
|
|
|
from tiramisu.error import PropertiesOptionError, RequirementError
|
|
|
|
from py.test import raises
|
|
|
|
|
|
|
|
|
|
|
|
def test_requires():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
2013-05-31 23:29:20 +02:00
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.ip_address_service
|
|
|
|
c.activate_service = False
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-05-31 23:29:20 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
2013-12-09 18:56:29 +01:00
|
|
|
def test_requires_invalid():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires='string')")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'unknown': True}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'action': 'disabled'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'expected': False, 'action': 'disabled'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': 'string'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'transitive': 'string'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': False, 'action': 'disabled', 'same_action': 'string'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': 'string', 'expected': False, 'action': 'disabled'}])")
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': 'string', 'action': 'disabled'}])")
|
|
|
|
|
|
|
|
|
2013-06-13 14:43:51 +02:00
|
|
|
def test_requires_same_action():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'new'}])
|
2013-06-13 14:43:51 +02:00
|
|
|
|
|
|
|
d = IPOption('ip_address_service_web', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': b, 'expected': False,
|
|
|
|
'action': 'disabled', 'inverse': False,
|
|
|
|
'transitive': True, 'same_action': False}])
|
2013-06-13 14:43:51 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.cfgimpl_get_settings().append('new')
|
|
|
|
c.activate_service
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-13 14:43:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['new']
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-13 14:43:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
2013-07-03 15:04:15 +02:00
|
|
|
def test_multiple_requires():
|
|
|
|
a = StrOption('activate_service', '')
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
|
|
|
{'option': a, 'expected': 'ok', 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.ip_address_service
|
|
|
|
c.activate_service = 'yes'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-07-03 15:04:15 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = 'ok'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-07-03 15:04:15 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = 'no'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
|
2013-09-02 17:13:07 +02:00
|
|
|
def test_multiple_requires_cumulative():
|
|
|
|
a = StrOption('activate_service', '')
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
|
|
|
|
{'option': a, 'expected': 'yes', 'action': 'hidden'}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.ip_address_service
|
|
|
|
c.activate_service = 'yes'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['hidden', 'disabled'])
|
|
|
|
|
|
|
|
c.activate_service = 'ok'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.activate_service = 'no'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
|
2013-09-02 19:47:00 +02:00
|
|
|
def test_multiple_requires_cumulative_inverse():
|
|
|
|
a = StrOption('activate_service', '')
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
|
|
|
|
{'option': a, 'expected': 'yes', 'action': 'hidden', 'inverse': True}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['hidden', 'disabled'])
|
|
|
|
c.activate_service = 'yes'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.activate_service = 'ok'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['hidden', 'disabled'])
|
|
|
|
|
|
|
|
c.activate_service = 'no'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
|
|
|
except PropertiesOptionError as err:
|
|
|
|
props = err.proptype
|
|
|
|
assert set(props) == set(['hidden', 'disabled'])
|
|
|
|
|
|
|
|
|
2013-07-03 15:04:15 +02:00
|
|
|
def test_multiple_requires_inverse():
|
|
|
|
a = StrOption('activate_service', '')
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
|
|
|
|
{'option': a, 'expected': 'ok', 'action': 'disabled', 'inverse': True}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-07-03 15:04:15 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = 'yes'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.activate_service = 'ok'
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.activate_service = 'no'
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-07-03 15:04:15 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
2013-06-10 15:19:00 +02:00
|
|
|
def test_requires_transitive():
|
2013-05-31 23:29:20 +02:00
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
2013-06-10 15:19:00 +02:00
|
|
|
|
2013-05-31 23:29:20 +02:00
|
|
|
d = IPOption('ip_address_service_web', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
2013-05-31 23:29:20 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.activate_service
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-05-31 23:29:20 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-05-31 23:29:20 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
2013-06-10 15:19:00 +02:00
|
|
|
def test_requires_transitive_bis():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
abis = BoolOption('activate_service_bis', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
2013-06-10 15:19:00 +02:00
|
|
|
|
|
|
|
d = IPOption('ip_address_service_web', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
|
2013-06-10 15:19:00 +02:00
|
|
|
od = OptionDescription('service', '', [a, abis, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
#
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-10 15:19:00 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-10 15:19:00 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
|
|
|
def test_requires_transitive_hidden_disabled():
|
2013-05-31 23:29:20 +02:00
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'hidden'}])
|
2013-05-31 23:29:20 +02:00
|
|
|
d = IPOption('ip_address_service_web', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
|
2013-05-31 23:29:20 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.activate_service
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-05-31 23:29:20 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['hidden']
|
|
|
|
raises(RequirementError, 'c.ip_address_service_web')
|
|
|
|
|
|
|
|
|
2013-06-10 15:19:00 +02:00
|
|
|
def test_requires_not_transitive():
|
2013-05-31 23:29:20 +02:00
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = BoolOption('activate_service_web', '', True,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
2013-05-31 23:29:20 +02:00
|
|
|
d = IPOption('ip_address_service_web', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': b, 'expected': False,
|
|
|
|
'action': 'disabled', 'transitive': False}])
|
2013-05-31 23:29:20 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.activate_service
|
|
|
|
c.activate_service_web
|
|
|
|
c.ip_address_service_web
|
|
|
|
c.activate_service = False
|
|
|
|
#
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.activate_service_web
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-05-31 23:29:20 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
#
|
|
|
|
c.ip_address_service_web
|
2013-06-13 12:15:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_requires_None():
|
|
|
|
a = BoolOption('activate_service', '')
|
|
|
|
b = IPOption('ip_address_service', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': None, 'action': 'disabled'}])
|
2013-06-13 12:15:46 +02:00
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-13 12:15:46 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
c.activate_service = False
|
|
|
|
c.ip_address_service
|
2013-06-28 11:59:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_requires_multi_disabled():
|
|
|
|
a = BoolOption('activate_service', '')
|
|
|
|
b = IntOption('num_service', '')
|
|
|
|
c = IPOption('ip_address_service', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': True, 'action': 'disabled'},
|
|
|
|
{'option': b, 'expected': 1, 'action': 'disabled'}])
|
2013-06-28 11:59:51 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, c])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.activate_service = True
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = False
|
|
|
|
c.ip_address_service
|
|
|
|
|
|
|
|
c.num_service = 1
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = True
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
2013-06-29 18:41:14 +02:00
|
|
|
|
2013-06-28 11:59:51 +02:00
|
|
|
def test_requires_multi_disabled_inverse():
|
|
|
|
a = BoolOption('activate_service', '')
|
|
|
|
b = IntOption('num_service', '')
|
|
|
|
c = IPOption('ip_address_service', '',
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=[{'option': a, 'expected': True,
|
|
|
|
'action': 'disabled', 'inverse': True},
|
|
|
|
{'option': b, 'expected': 1,
|
|
|
|
'action': 'disabled', 'inverse': True}])
|
2013-06-28 11:59:51 +02:00
|
|
|
od = OptionDescription('service', '', [a, b, c])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = True
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = False
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.num_service = 1
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
c.ip_address_service
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-28 11:59:51 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
c.activate_service = True
|
|
|
|
c.ip_address_service
|
2013-06-29 18:41:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_requires_multi_disabled_2():
|
|
|
|
a = BoolOption('a', '')
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
c = BoolOption('c', '')
|
|
|
|
d = BoolOption('d', '')
|
|
|
|
e = BoolOption('e', '')
|
|
|
|
f = BoolOption('f', '')
|
|
|
|
g = BoolOption('g', '')
|
|
|
|
h = BoolOption('h', '')
|
|
|
|
i = BoolOption('i', '')
|
|
|
|
j = BoolOption('j', '')
|
|
|
|
k = BoolOption('k', '')
|
|
|
|
l = BoolOption('l', '')
|
|
|
|
m = BoolOption('m', '')
|
|
|
|
list_bools = [a, b, c, d, e, f, g, h, i, j, k, l, m]
|
|
|
|
requires = []
|
|
|
|
for boo in list_bools:
|
|
|
|
requires.append({'option': boo, 'expected': True, 'action': 'disabled'})
|
|
|
|
z = IPOption('z', '', requires=requires)
|
|
|
|
y = copy(list_bools)
|
|
|
|
y.append(z)
|
|
|
|
od = OptionDescription('service', '', y)
|
|
|
|
cfg = Config(od)
|
|
|
|
cfg.read_write()
|
|
|
|
|
|
|
|
cfg.z
|
|
|
|
for boo in list_bools:
|
|
|
|
setattr(cfg, boo._name, True)
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-29 18:41:14 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
for boo in list_bools:
|
|
|
|
setattr(cfg, boo._name, False)
|
|
|
|
if boo == m:
|
|
|
|
cfg.z
|
|
|
|
else:
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-29 18:41:14 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
|
|
|
|
|
|
|
|
def test_requires_multi_disabled_inverse_2():
|
|
|
|
a = BoolOption('a', '')
|
|
|
|
b = BoolOption('b', '')
|
|
|
|
c = BoolOption('c', '')
|
|
|
|
d = BoolOption('d', '')
|
|
|
|
e = BoolOption('e', '')
|
|
|
|
f = BoolOption('f', '')
|
|
|
|
g = BoolOption('g', '')
|
|
|
|
h = BoolOption('h', '')
|
|
|
|
i = BoolOption('i', '')
|
|
|
|
j = BoolOption('j', '')
|
|
|
|
k = BoolOption('k', '')
|
|
|
|
l = BoolOption('l', '')
|
|
|
|
m = BoolOption('m', '')
|
|
|
|
list_bools = [a, b, c, d, e, f, g, h, i, j, k, l, m]
|
|
|
|
requires = []
|
|
|
|
for boo in list_bools:
|
|
|
|
requires.append({'option': boo, 'expected': True, 'action': 'disabled',
|
|
|
|
'inverse': True})
|
|
|
|
z = IPOption('z', '', requires=requires)
|
|
|
|
y = copy(list_bools)
|
|
|
|
y.append(z)
|
|
|
|
od = OptionDescription('service', '', y)
|
|
|
|
cfg = Config(od)
|
|
|
|
cfg.read_write()
|
|
|
|
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-29 18:41:14 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
for boo in list_bools:
|
|
|
|
setattr(cfg, boo._name, True)
|
|
|
|
if boo == m:
|
|
|
|
cfg.z
|
|
|
|
else:
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-29 18:41:14 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
|
|
|
for boo in list_bools:
|
|
|
|
setattr(cfg, boo._name, False)
|
|
|
|
props = []
|
|
|
|
try:
|
|
|
|
cfg.z
|
2013-08-28 11:33:43 +02:00
|
|
|
except PropertiesOptionError as err:
|
2013-06-29 18:41:14 +02:00
|
|
|
props = err.proptype
|
|
|
|
assert props == ['disabled']
|
2013-08-22 22:46:02 +02:00
|
|
|
|
|
|
|
|
2014-01-30 22:55:15 +01:00
|
|
|
def test_requires_requirement_append():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('service', '', [a, b])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
str(c.cfgimpl_get_settings())
|
|
|
|
str(c.cfgimpl_get_settings()[b])
|
|
|
|
raises(ValueError, 'c.cfgimpl_get_settings()[b].append("disabled")')
|
|
|
|
c.activate_service = False
|
|
|
|
# disabled is now set, test to remove disabled before store in storage
|
|
|
|
c.cfgimpl_get_settings()[b].append("test")
|
2013-08-22 22:57:32 +02:00
|
|
|
|
|
|
|
|
2013-12-09 18:56:29 +01:00
|
|
|
def test_requires_different_inverse():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}])")
|
|
|
|
|
|
|
|
|
2013-08-22 22:57:32 +02:00
|
|
|
def test_requires_recursive_path():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('base', '', [od1])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
raises(RequirementError, 'c.service.a')
|
2013-08-24 16:30:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_properties_with_None_path():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '',
|
|
|
|
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
|
|
|
od = OptionDescription('base', '', [od1])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
raises(ValueError, "c.cfgimpl_get_settings()._getproperties(a)")
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_item():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
b = IPOption('ip_address_service', '')
|
|
|
|
od1 = OptionDescription('service', '', [a, b])
|
|
|
|
od = OptionDescription('base', '', [od1])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
raises(ValueError, 'c.cfgimpl_get_settings()[a] = ("test",)')
|
2013-09-02 19:47:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_properties_conflict():
|
|
|
|
a = BoolOption('activate_service', '', True)
|
|
|
|
raises(ValueError, "IPOption('ip_address_service', '', properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
|
|
|
|
raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
|