* to "reset" a value, now you just have to delete it
config.unwrap_from_path("string").reset(config) => del(config.string) * add cache for value/setting to 5 secds to "reset" cache just do: config.cfgimpl_clean_cache() * can desactivate cache by removing "expire" property
This commit is contained in:
@ -20,7 +20,7 @@ def make_description_freeze():
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=[True], multi=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',),
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
@ -136,3 +136,12 @@ def test_freeze_get_multi():
|
||||
except PropertiesOptionError, err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_force_store_value():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
opt = conf.unwrap_from_path('wantref')
|
||||
assert conf.cfgimpl_get_values().getowner(opt) == 'default'
|
||||
conf.wantref
|
||||
assert conf.cfgimpl_get_values().getowner(opt) == 'user'
|
||||
|
@ -57,7 +57,7 @@ def test_reset():
|
||||
config.string = "foo"
|
||||
assert config.string == "foo"
|
||||
assert config.cfgimpl_get_values().getowner(s) == owners.user
|
||||
config.unwrap_from_path("string").reset(config)
|
||||
del(config.string)
|
||||
assert config.string == 'string'
|
||||
assert config.cfgimpl_get_values().getowner(s) == owners.default
|
||||
|
||||
@ -67,13 +67,13 @@ def test_reset_with_multi():
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
# config.string = []
|
||||
config.unwrap_from_path("string").reset(config)
|
||||
del(config.string)
|
||||
assert config.string == ["string"]
|
||||
assert config.cfgimpl_get_values().getowner(s) == 'default'
|
||||
config.string = ["eggs", "spam", "foo"]
|
||||
assert config.cfgimpl_get_values().getowner(s) == 'user'
|
||||
config.string = []
|
||||
config.unwrap_from_path("string").reset(config)
|
||||
del(config.string)
|
||||
# assert config.string == ["string"]
|
||||
assert config.cfgimpl_get_values().getowner(s) == 'default'
|
||||
raises(ValueError, "config.string = None")
|
||||
|
@ -1,23 +1,25 @@
|
||||
# coding: utf-8
|
||||
import autopath
|
||||
from tiramisu.config import *
|
||||
from tiramisu.option import *
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, \
|
||||
StrOption, OptionDescription
|
||||
|
||||
from py.test import raises
|
||||
|
||||
|
||||
def make_description():
|
||||
numero_etab = StrOption('numero_etab', "identifiant de l'établissement")
|
||||
nom_machine = StrOption('nom_machine', "nom de la machine", default="eoleng")
|
||||
nombre_interfaces = IntOption('nombre_interfaces', "nombre d'interfaces à activer",
|
||||
default=1)
|
||||
default=1)
|
||||
activer_proxy_client = BoolOption('activer_proxy_client', "utiliser un proxy",
|
||||
default=False)
|
||||
mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur",
|
||||
default=False)
|
||||
adresse_serveur_ntp = StrOption('serveur_ntp', "adresse serveur ntp", multi=True)
|
||||
time_zone = ChoiceOption('time_zone', 'fuseau horaire du serveur',
|
||||
('Paris', 'Londres'), 'Paris')
|
||||
('Paris', 'Londres'), 'Paris')
|
||||
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
|
||||
@ -27,32 +29,34 @@ def make_description():
|
||||
interface1.set_group_type(groups.family)
|
||||
|
||||
general = OptionDescription('general', '', [numero_etab, nom_machine,
|
||||
nombre_interfaces, activer_proxy_client,
|
||||
mode_conteneur_actif, adresse_serveur_ntp,
|
||||
time_zone])
|
||||
nombre_interfaces, activer_proxy_client,
|
||||
mode_conteneur_actif, adresse_serveur_ntp,
|
||||
time_zone])
|
||||
general.set_group_type(groups.family)
|
||||
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1])
|
||||
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole] )
|
||||
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
|
||||
return descr
|
||||
|
||||
|
||||
def test_base_config():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
assert config.creole.general.activer_proxy_client == False
|
||||
assert config.creole.general.activer_proxy_client is False
|
||||
assert config.creole.general.nom_machine == "eoleng"
|
||||
assert config.find_first(byname='nom_machine', type_='value') == "eoleng"
|
||||
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
|
||||
'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None,
|
||||
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
|
||||
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
|
||||
'eoleng', 'general.activer_proxy_client': False}
|
||||
'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None,
|
||||
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
|
||||
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
|
||||
'eoleng', 'general.activer_proxy_client': False}
|
||||
assert config.creole.make_dict() == result
|
||||
result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
|
||||
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
|
||||
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
|
||||
False, 'nombre_interfaces': 1}
|
||||
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
|
||||
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
|
||||
False, 'nombre_interfaces': 1}
|
||||
assert config.creole.make_dict(flatten=True) == result
|
||||
|
||||
|
||||
def test_get_group_type():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
@ -62,6 +66,7 @@ def test_get_group_type():
|
||||
assert isinstance(grp.get_group_type(), groups.GroupType)
|
||||
raises(TypeError, 'grp.set_group_type(groups.default)')
|
||||
|
||||
|
||||
def test_iter_on_groups():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
@ -69,8 +74,9 @@ def test_iter_on_groups():
|
||||
group_names = [res[0] for res in result]
|
||||
assert group_names == ['general', 'interface1']
|
||||
|
||||
|
||||
def test_iter_on_empty_group():
|
||||
config = Config(OptionDescription("name", "descr", [] ))
|
||||
config = Config(OptionDescription("name", "descr", []))
|
||||
result = list(config.iter_groups())
|
||||
assert result == []
|
||||
for i in config.iter_groups():
|
||||
@ -79,6 +85,7 @@ def test_iter_on_empty_group():
|
||||
pass
|
||||
assert [] == list(config)
|
||||
|
||||
|
||||
def test_groups_with_master():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
@ -86,26 +93,30 @@ def test_groups_with_master():
|
||||
interface1.set_group_type(groups.master)
|
||||
assert interface1.get_group_type() == groups.master
|
||||
|
||||
|
||||
def test_groups_with_master_in_config():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.set_group_type(groups.master)
|
||||
cfg = Config(interface1)
|
||||
Config(interface1)
|
||||
assert interface1.get_group_type() == groups.master
|
||||
|
||||
|
||||
def test_allowed_groups():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
raises(ValueError, "interface1.set_group_type('toto')")
|
||||
|
||||
|
||||
def test_master_not_valid_name():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
invalid_group = OptionDescription('interface1', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
raises(ValueError, "invalid_group.set_group_type(groups.master)")
|
||||
|
||||
|
||||
def test_sub_group_in_master_group():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
@ -113,14 +124,15 @@ def test_sub_group_in_master_group():
|
||||
invalid_group = OptionDescription('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0])
|
||||
raises(ValueError, "invalid_group.set_group_type(groups.master)")
|
||||
|
||||
|
||||
def test_group_always_has_multis():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
|
||||
group = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
raises(ValueError, "group.set_group_type(groups.master)")
|
||||
|
||||
#____________________________________________________________
|
||||
|
||||
#____________________________________________________________
|
||||
def test_values_with_master_and_slaves():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
@ -136,6 +148,7 @@ def test_values_with_master_and_slaves():
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == ["192.168.230.145"]
|
||||
assert cfg.cfgimpl_get_values().getowner(opt) == owner
|
||||
|
||||
|
||||
def test_reset_values_with_master_and_slaves():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
@ -149,6 +162,6 @@ def test_reset_values_with_master_and_slaves():
|
||||
assert cfg.cfgimpl_get_values().getowner(opt) == owners.default
|
||||
cfg.ip_admin_eth0.ip_admin_eth0.append("192.168.230.145")
|
||||
assert cfg.cfgimpl_get_values().getowner(opt) == owner
|
||||
cfg.cfgimpl_get_values().reset(opt)
|
||||
del(cfg.ip_admin_eth0.ip_admin_eth0)
|
||||
assert cfg.cfgimpl_get_values().getowner(opt) == owners.default
|
||||
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||
|
Reference in New Issue
Block a user