better sqlalchemy integration
This commit is contained in:
@ -82,7 +82,7 @@ def make_description4():
|
||||
|
||||
def test_mandatory_ro():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man001')
|
||||
config.read_only()
|
||||
prop = []
|
||||
try:
|
||||
@ -94,21 +94,31 @@ def test_mandatory_ro():
|
||||
config.str1 = 'yes'
|
||||
config.read_only()
|
||||
assert config.str1 == 'yes'
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_rw():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man002')
|
||||
config.read_write()
|
||||
#not mandatory in rw
|
||||
config.str1
|
||||
config.str1 = 'yes'
|
||||
assert config.str1 == 'yes'
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_default():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man003')
|
||||
config.read_only()
|
||||
#not mandatory in rw
|
||||
config.str
|
||||
@ -125,11 +135,16 @@ def test_mandatory_default():
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_delete():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man004')
|
||||
config.read_only()
|
||||
config.str
|
||||
try:
|
||||
@ -150,12 +165,17 @@ def test_mandatory_delete():
|
||||
assert 'mandatory' in prop
|
||||
del(config.str)
|
||||
assert config.str1 == 'yes'
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
#valeur vide : None, '', u'', ...
|
||||
def test_mandatory_none():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man005')
|
||||
config.str1 = None
|
||||
assert config.getowner(config.unwrap_from_path('str1')) == 'user'
|
||||
config.read_only()
|
||||
@ -165,11 +185,16 @@ def test_mandatory_none():
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_empty():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man006')
|
||||
config.str1 = ''
|
||||
assert config.getowner(config.unwrap_from_path('str1')) == 'user'
|
||||
config.read_only()
|
||||
@ -179,11 +204,16 @@ def test_mandatory_empty():
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_multi_none():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man007')
|
||||
config.str3 = [None]
|
||||
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
||||
config.read_only()
|
||||
@ -203,11 +233,16 @@ def test_mandatory_multi_none():
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_multi_empty():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man008')
|
||||
config.str3 = []
|
||||
assert config.getowner(config.unwrap_from_path('str3')) == 'user'
|
||||
config.read_only()
|
||||
@ -239,11 +274,16 @@ def test_mandatory_multi_empty():
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_multi_empty_allow_empty_list():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man009')
|
||||
config.str4 = []
|
||||
assert config.getowner(config.unwrap_from_path('str4')) == 'user'
|
||||
config.read_only()
|
||||
@ -271,19 +311,29 @@ def test_mandatory_multi_empty_allow_empty_list():
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_multi_append():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man010')
|
||||
config.str3 = ['yes']
|
||||
config.read_write()
|
||||
config.str3.append(None)
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_disabled():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man011')
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.str1
|
||||
config.read_only()
|
||||
@ -300,11 +350,16 @@ def test_mandatory_disabled():
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert set(prop) == set(['disabled', 'mandatory'])
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_unicode():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man012')
|
||||
config.unicode2
|
||||
config.read_only()
|
||||
prop = []
|
||||
@ -322,11 +377,16 @@ def test_mandatory_unicode():
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert prop == ['mandatory']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
||||
|
||||
def test_mandatory_warnings_ro():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man013')
|
||||
config.str = ''
|
||||
config.read_only()
|
||||
proc = []
|
||||
@ -341,11 +401,16 @@ def test_mandatory_warnings_ro():
|
||||
config.read_only()
|
||||
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_rw():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man100')
|
||||
config.str = ''
|
||||
config.read_write()
|
||||
config.str
|
||||
@ -354,7 +419,7 @@ def test_mandatory_warnings_rw():
|
||||
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())
|
||||
delete_session('config', 'man100')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -362,7 +427,7 @@ def test_mandatory_warnings_rw():
|
||||
|
||||
def test_mandatory_warnings_disabled():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man101')
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
@ -372,7 +437,7 @@ def test_mandatory_warnings_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())
|
||||
delete_session('config', 'man101')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -380,7 +445,7 @@ def test_mandatory_warnings_disabled():
|
||||
|
||||
def test_mandatory_warnings_hidden():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man102')
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
@ -391,7 +456,7 @@ def test_mandatory_warnings_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())
|
||||
delete_session('config', 'man102')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -399,7 +464,7 @@ def test_mandatory_warnings_hidden():
|
||||
|
||||
def test_mandatory_warnings_frozen():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man103')
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
@ -409,7 +474,7 @@ def test_mandatory_warnings_frozen():
|
||||
config.read_only()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
delete_session('config', 'man103')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -423,12 +488,12 @@ def test_mandatory_master():
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o)
|
||||
config = Config(o, session_id='man104')
|
||||
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())
|
||||
delete_session('config', 'man104')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -442,10 +507,10 @@ def test_mandatory_warnings_master():
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o)
|
||||
config = Config(o, session_id='man105')
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
delete_session('config', 'man105')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -458,7 +523,7 @@ def test_mandatory_master_empty():
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o)
|
||||
config = Config(o, session_id='man106')
|
||||
config.read_write()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
@ -489,7 +554,7 @@ def test_mandatory_master_empty():
|
||||
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())
|
||||
delete_session('config', 'man106')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -502,7 +567,7 @@ def test_mandatory_warnings_master_empty():
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o)
|
||||
config = Config(o, session_id='man107')
|
||||
config.read_write()
|
||||
config.ip_admin_eth0.ip_admin_eth0.append()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == [None]
|
||||
@ -520,7 +585,7 @@ def test_mandatory_warnings_master_empty():
|
||||
config.ip_admin_eth0.ip_admin_eth0 = ['ip']
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == []
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
delete_session('config', 'man107')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -533,7 +598,7 @@ def test_mandatory_slave():
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o)
|
||||
config = Config(o, session_id='man108')
|
||||
config.read_only()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
@ -556,7 +621,7 @@ def test_mandatory_slave():
|
||||
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())
|
||||
delete_session('config', 'man108')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -569,7 +634,7 @@ def test_mandatory_warnings_slave():
|
||||
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
o = OptionDescription('o', '', [interface1])
|
||||
config = Config(o)
|
||||
config = Config(o, session_id='man109')
|
||||
config.read_only()
|
||||
assert config.ip_admin_eth0.ip_admin_eth0 == []
|
||||
assert config.ip_admin_eth0.netmask_admin_eth0 == []
|
||||
@ -579,7 +644,7 @@ def test_mandatory_warnings_slave():
|
||||
config.ip_admin_eth0.ip_admin_eth0.append('ip')
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['ip_admin_eth0.netmask_admin_eth0']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
delete_session('config', 'man109')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -587,7 +652,7 @@ def test_mandatory_warnings_slave():
|
||||
|
||||
def test_mandatory_warnings_symlink():
|
||||
descr = make_description_sym()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man110')
|
||||
config.str = ''
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
@ -597,7 +662,7 @@ def test_mandatory_warnings_symlink():
|
||||
config.read_only()
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str', 'str1', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
delete_session('config', 'man110')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -605,7 +670,7 @@ def test_mandatory_warnings_symlink():
|
||||
|
||||
def test_mandatory_warnings_validate():
|
||||
descr = make_description3()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man111')
|
||||
config.str = ''
|
||||
raises(ValueError, "list(config.cfgimpl_get_values().mandatory_warnings())")
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings(validate=False)) == ['str', 'str1', 'str3', 'unicode1', 'int1']
|
||||
@ -613,7 +678,7 @@ def test_mandatory_warnings_validate():
|
||||
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())
|
||||
delete_session('config', 'man111')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -621,13 +686,13 @@ def test_mandatory_warnings_validate():
|
||||
|
||||
def test_mandatory_warnings_validate_empty():
|
||||
descr = make_description2()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man112')
|
||||
config.str = ''
|
||||
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())
|
||||
delete_session('config', 'man112')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -635,7 +700,7 @@ def test_mandatory_warnings_validate_empty():
|
||||
|
||||
def test_mandatory_warnings_requires():
|
||||
descr = make_description4()
|
||||
config = Config(descr)
|
||||
config = Config(descr, session_id='man113')
|
||||
config.str = ''
|
||||
config.read_write()
|
||||
config.str
|
||||
@ -646,7 +711,7 @@ def test_mandatory_warnings_requires():
|
||||
config.str = 'yes'
|
||||
assert list(config.cfgimpl_get_values().mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
try:
|
||||
delete_session('config', config.impl_getsessionid())
|
||||
delete_session('config', 'man113')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
@ -655,13 +720,13 @@ def test_mandatory_warnings_requires():
|
||||
def test_mandatory_od_disabled():
|
||||
descr = make_description()
|
||||
od = OptionDescription('od', '', [descr])
|
||||
config = Config(od)
|
||||
config = Config(od, session_id='man114')
|
||||
config.read_only()
|
||||
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())
|
||||
delete_session('config', 'man114')
|
||||
except ValueError:
|
||||
pass
|
||||
del(config)
|
||||
|
Reference in New Issue
Block a user