update sqlalchemy storage for values et settings
This commit is contained in:
@ -6,7 +6,7 @@ from tiramisu.setting import groups
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, \
|
||||
StrOption, OptionDescription
|
||||
from test.test_state import _diff_opts, _diff_conf
|
||||
from .test_state import _diff_opts, _diff_conf
|
||||
from py.test import raises
|
||||
|
||||
|
||||
|
@ -1300,7 +1300,7 @@ def test_state_config():
|
||||
|
||||
try:
|
||||
delete_session('config', '29090938')
|
||||
except ConfigError:
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ from tiramisu.config import Config
|
||||
from tiramisu.option import IntOption, StrOption, UnicodeOption, OptionDescription, SymLinkOption
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu.storage import delete_session
|
||||
|
||||
|
||||
def make_description():
|
||||
@ -352,6 +353,11 @@ def test_mandatory_warnings_rw():
|
||||
config.str = 'a'
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == ['str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_warnings_disabled():
|
||||
@ -365,6 +371,11 @@ def test_mandatory_warnings_disabled():
|
||||
setting[descr.str].append('disabled')
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == ['str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_warnings_hidden():
|
||||
@ -379,6 +390,11 @@ def test_mandatory_warnings_hidden():
|
||||
setting[descr.str].append('hidden')
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings(force_permissive=True)) == ['str', 'str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_warnings_frozen():
|
||||
@ -392,6 +408,11 @@ def test_mandatory_warnings_frozen():
|
||||
setting[descr.str].append('frozen')
|
||||
config.read_only()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_master():
|
||||
@ -406,6 +427,11 @@ def test_mandatory_master():
|
||||
config.read_only()
|
||||
raises(PropertiesOptionError, 'config.ip_admin_eth0.ip_admin_eth0')
|
||||
raises(PropertiesOptionError, 'config.ip_admin_eth0.netmask_admin_eth0')
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_master_empty():
|
||||
@ -445,6 +471,11 @@ def test_mandatory_master_empty():
|
||||
config.read_only()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == ['ip']
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_slave():
|
||||
@ -476,6 +507,11 @@ def test_mandatory_slave():
|
||||
config.read_only()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == ['ip']
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == ['ip']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_warnings_symlink():
|
||||
@ -489,6 +525,11 @@ def test_mandatory_warnings_symlink():
|
||||
setting[descr.str].append('frozen')
|
||||
config.read_only()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_warnings_validate():
|
||||
@ -500,6 +541,11 @@ def test_mandatory_warnings_validate():
|
||||
config.str = 'test'
|
||||
raises(ValueError, "list(config.cfgimpl_get_values().mandatory_warnings())")
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings(validate=False)) == ['str1', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_warnings_validate_empty():
|
||||
@ -509,6 +555,11 @@ def test_mandatory_warnings_validate_empty():
|
||||
config.read_only()
|
||||
raises(ConfigError, "list(config.cfgimpl_get_values().mandatory_warnings())")
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings(validate=False)) == ['str', 'str1', 'str3', 'unicode1']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_warnings_requires():
|
||||
@ -523,6 +574,11 @@ def test_mandatory_warnings_requires():
|
||||
config.read_write()
|
||||
config.str = 'yes'
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_od_disabled():
|
||||
@ -533,3 +589,8 @@ def test_mandatory_od_disabled():
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
|
||||
config.cfgimpl_get_settings()[descr].append('disabled')
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == []
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
@ -301,7 +301,7 @@ def test_state_config():
|
||||
_diff_conf(cfg, q)
|
||||
try:
|
||||
delete_session('config', '29090931')
|
||||
except ConfigError:
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
@ -330,7 +330,7 @@ def test_state_config2():
|
||||
_diff_conf(cfg, q)
|
||||
try:
|
||||
delete_session('config', '29090939')
|
||||
except ConfigError:
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
@ -370,7 +370,7 @@ def test_state_properties():
|
||||
_diff_conf(cfg, q)
|
||||
try:
|
||||
delete_session('config', '29090932')
|
||||
except ConfigError:
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
@ -391,7 +391,7 @@ def test_state_values():
|
||||
assert q.val1 is False
|
||||
try:
|
||||
delete_session('config', '29090933')
|
||||
except ConfigError:
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
@ -414,7 +414,7 @@ def test_state_values_owner():
|
||||
assert q.getowner(nval1) == owners.newowner
|
||||
try:
|
||||
delete_session('config', '29090934')
|
||||
except ConfigError:
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
@ -433,7 +433,7 @@ def test_state_metaconfig():
|
||||
delete_session('config', '29090935')
|
||||
delete_session('config', '29090936')
|
||||
delete_session('config', '29090937')
|
||||
except ConfigError:
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
@ -454,7 +454,7 @@ def test_state_groupconfig():
|
||||
delete_session('config', '29090935')
|
||||
delete_session('config', '29090936')
|
||||
delete_session('config', '29090937')
|
||||
except ConfigError:
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
|
@ -58,7 +58,7 @@ def test_delete_session_persistent():
|
||||
pass
|
||||
else:
|
||||
assert 'test_persistent' in list_sessions('config')
|
||||
delete_session('test_persistent')
|
||||
delete_session('config', 'test_persistent')
|
||||
assert 'test_persistent' not in list_sessions('config')
|
||||
|
||||
|
||||
@ -67,7 +67,6 @@ def test_create_persistent_retrieve():
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
@ -77,14 +76,14 @@ def test_create_persistent_retrieve():
|
||||
assert c.b is True
|
||||
del(c)
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
assert c.b is True
|
||||
assert 'test_persistent' in list_sessions('config')
|
||||
delete_session('test_persistent')
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
assert c.b is None
|
||||
delete_session('test_persistent')
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
|
||||
|
||||
def test_two_persistent():
|
||||
@ -92,11 +91,11 @@ def test_two_persistent():
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
c.cfgimpl_get_settings().remove('cache')
|
||||
c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
c2.cfgimpl_get_settings().remove('cache')
|
||||
assert c.b is None
|
||||
@ -104,10 +103,40 @@ def test_two_persistent():
|
||||
c.b = False
|
||||
assert c.b is False
|
||||
assert c2.b is False
|
||||
c.b = True
|
||||
c2.b = True
|
||||
assert c.b is True
|
||||
assert c2.b is True
|
||||
delete_session('test_persistent')
|
||||
delete_session('config', 'test_persistent')
|
||||
|
||||
|
||||
def test_create_persistent_retrieve_owner():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
assert c.getowner(b) == owners.default
|
||||
c.b = True
|
||||
assert c.b is True
|
||||
assert c.getowner(b) == owners.user
|
||||
owners.addowner('persistentowner')
|
||||
c.cfgimpl_get_values().setowner(b, owners.persistentowner)
|
||||
assert c.getowner(b) == owners.persistentowner
|
||||
del(c)
|
||||
#
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
c.cfgimpl_get_values().setowner(b, owners.persistentowner)
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
#
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
assert c.b is None
|
||||
assert c.getowner(b) == owners.default
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
|
||||
|
||||
def test_two_persistent_owner():
|
||||
@ -122,16 +151,40 @@ def test_two_persistent_owner():
|
||||
else:
|
||||
c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||
c2.cfgimpl_get_settings().remove('cache')
|
||||
owners.addowner('persistent')
|
||||
assert c.getowner(b) == owners.default
|
||||
assert c2.getowner(b) == owners.default
|
||||
c.b = False
|
||||
assert c.getowner(b) == owners.user
|
||||
assert c2.getowner(b) == owners.user
|
||||
owners.addowner('persistent')
|
||||
c.cfgimpl_get_values().setowner(b, owners.persistent)
|
||||
assert c.getowner(b) == owners.persistent
|
||||
assert c2.getowner(b) == owners.persistent
|
||||
delete_session('test_persistent')
|
||||
delete_session('config', 'test_persistent')
|
||||
|
||||
|
||||
def test_create_persistent_retrieve_information():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
try:
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
except ValueError:
|
||||
# storage is not persistent
|
||||
pass
|
||||
else:
|
||||
c.impl_set_information('info', 'string')
|
||||
assert c.impl_get_information('info') == 'string'
|
||||
del(c)
|
||||
#
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
assert c.impl_get_information('info') == 'string'
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
#
|
||||
c = Config(o, session_id='test_persistent', persistent=True)
|
||||
assert c.impl_get_information('info', None) == None
|
||||
delete_session('config', c.impl_getsessionid())
|
||||
del(c)
|
||||
|
||||
|
||||
def test_two_persistent_information():
|
||||
@ -150,4 +203,4 @@ def test_two_persistent_information():
|
||||
c2.cfgimpl_get_settings().remove('cache')
|
||||
c2.cfgimpl_get_settings().remove('cache')
|
||||
assert c2.impl_get_information('info') == 'string'
|
||||
delete_session('test_persistent')
|
||||
delete_session('config', 'test_persistent')
|
||||
|
Reference in New Issue
Block a user