tiramisu/tests/test_option_owner.py

254 lines
11 KiB
Python
Raw Normal View History

2017-07-09 09:49:03 +02:00
from .autopath import do_autopath
2015-07-24 17:54:10 +02:00
do_autopath()
2019-12-24 15:24:20 +01:00
import pytest
2016-01-25 16:22:28 +01:00
from tiramisu.setting import owners, groups
2018-03-19 08:33:53 +01:00
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
2019-02-23 19:06:23 +01:00
StrOption, OptionDescription, SymLinkOption, Leadership, Config
2018-03-19 08:33:53 +01:00
from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, APIError
2018-10-31 08:00:19 +01:00
from tiramisu.storage import list_sessions
2020-01-22 20:46:18 +01:00
from .config import config_type, get_config, event_loop
2018-10-31 08:00:19 +01:00
2019-06-21 23:04:04 +02:00
owners.addowner("readonly2")
owners.addowner("new2")
def make_description():
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
2012-12-10 14:10:05 +01:00
gcdummy = BoolOption('dummy', 'dummy', default=False)
objspaceoption = ChoiceOption('objspace', 'Object space',
['std', 'thunk'], 'std')
booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0)
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)
2012-12-10 14:10:05 +01:00
wantref_option = BoolOption('wantref', 'Test requires', default=False)
wantframework_option = BoolOption('wantframework', 'Test requires',
2012-12-10 14:10:05 +01:00
default=False)
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
2012-12-10 14:10:05 +01:00
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
wantframework_option,
intoption, boolop])
return descr
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_default_owner(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
2012-12-10 14:10:05 +01:00
descr = OptionDescription('tiramisu', '', [gcdummy])
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('dummy').value.get() is False
assert await cfg.option('dummy').owner.get() == 'default'
await cfg.option('dummy').value.set(True)
owner = await cfg.owner.get()
assert await cfg.option('dummy').owner.get() == owner
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_hidden_owner():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('hidden',))
descr = OptionDescription('tiramisu', '', [gcdummy])
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
await cfg.property.read_write()
#with pytest.raises(PropertiesOptionError):
# await cfg.forcepermissive.option('dummy').owner.get()
#with pytest.raises(PropertiesOptionError):
# await cfg.option('dummy').owner.isdefault()
#with pytest.raises(PropertiesOptionError):
# await cfg.forcepermissive.option('dummy').owner.isdefault()
await cfg.permissive.add('hidden')
await cfg.forcepermissive.option('dummy').value.get()
await cfg.forcepermissive.option('dummy').owner.isdefault()
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_addowner(config_type):
2012-12-10 14:38:25 +01:00
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg_ori:
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy').value.get() is False
assert await cfg.option('dummy').owner.get() == 'default'
assert await cfg.option('dummy').owner.isdefault()
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.owner.set('gen_config')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('dummy').value.set(True)
assert await cfg.option('dummy').owner.get() == owners.gen_config
assert not await cfg.option('dummy').owner.isdefault()
assert not await list_sessions()
2012-12-10 14:38:25 +01:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_addowner_multiple_time():
2018-03-19 08:33:53 +01:00
owners.addowner("testowner2")
2020-01-22 20:46:18 +01:00
with pytest.raises(ConstError):
2019-12-24 15:24:20 +01:00
owners.addowner("testowner2")
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_delete_owner():
2018-03-19 08:33:53 +01:00
owners.addowner('deleted2')
2020-01-22 20:46:18 +01:00
with pytest.raises(ConstError):
2019-12-24 15:24:20 +01:00
del(owners.deleted2)
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_owner_is_not_a_string(config_type):
2012-12-10 14:10:05 +01:00
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('dummy').value.get() is False
assert await cfg.option('dummy').owner.get() == owners.default
assert await cfg.option('dummy').owner.get() == 'default'
if config_type == 'tiramisu':
assert isinstance(await cfg.option('dummy').owner.get(), owners.Owner)
await cfg.option('dummy').value.set(True)
assert await cfg.option('dummy').owner.get() == 'user'
assert not await list_sessions()
2013-08-23 09:29:42 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_setowner_without_valid_owner(config_type):
2013-08-23 09:29:42 +02:00
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('dummy').value.get() is False
assert await cfg.option('dummy').owner.get() == 'default'
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_setowner_for_value(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg_ori:
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy').value.get() is False
assert await cfg.option('dummy').owner.get() == 'default'
if config_type == 'tiramisu-api':
await cfg.send()
with pytest.raises(ConfigError):
await cfg_ori.option('dummy').owner.set('new2')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('dummy').value.set(False)
assert await cfg.option('dummy').owner.get() == owners.user
if config_type == 'tiramisu-api':
await cfg.send()
2019-12-24 15:24:20 +01:00
await cfg_ori.option('dummy').owner.set('new2')
2020-01-22 20:46:18 +01:00
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy').owner.get() == owners.new2
assert not await list_sessions()
2019-06-21 23:04:04 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_setowner_forbidden(config_type):
2018-09-12 21:05:14 +02:00
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg_ori:
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy').value.get() is False
assert await cfg.option('dummy').owner.get() == 'default'
if config_type == 'tiramisu-api':
await cfg.send()
with pytest.raises(ValueError):
await cfg_ori.owner.set('default')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('dummy').value.set(False)
if config_type == 'tiramisu-api':
await cfg.send()
with pytest.raises(ValueError):
await cfg_ori.option('dummy').owner.set('default')
cfg = await get_config(cfg_ori, config_type)
assert not await list_sessions()
2019-06-21 23:04:04 +02:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_setowner_read_only(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg_ori:
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy').value.get() is False
assert await cfg.option('dummy').owner.get() == 'default'
await cfg.option('dummy').value.set(False)
assert await cfg.option('dummy').owner.get() == owners.user
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.property.read_only()
with pytest.raises(PropertiesOptionError):
await cfg_ori.option('dummy').owner.set('readonly2')
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy').owner.get() == owners.user
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_setowner_optiondescription(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr1 = OptionDescription('tiramisu', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [descr1])
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg:
cfg = await get_config(cfg, config_type)
with pytest.raises(APIError):
await cfg.option('tiramisu').owner.get()
with pytest.raises(APIError):
await cfg.option('tiramisu').owner.set('user')
assert not await list_sessions()
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_setowner_symlinkoption(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False)
s = SymLinkOption('symdummy', gcdummy)
descr1 = OptionDescription('tiramisu', '', [gcdummy, s])
descr = OptionDescription('tiramisu', '', [descr1])
2020-01-22 20:46:18 +01:00
async with await Config(descr) as cfg_ori:
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('tiramisu.symdummy').owner.isdefault()
await cfg.option('tiramisu.dummy').value.set(True)
assert not await cfg.option('tiramisu.symdummy').owner.isdefault()
if config_type == 'tiramisu-api':
await cfg.send()
with pytest.raises(ConfigError):
await cfg_ori.option('tiramisu.symdummy').owner.set('user')
assert not await list_sessions()
2016-01-25 16:22:28 +01:00
2019-12-24 15:24:20 +01:00
@pytest.mark.asyncio
async def test_owner_leadership(config_type):
2016-01-25 16:22:28 +01:00
b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', multi=True)
2019-02-23 19:06:23 +01:00
descr = Leadership("int", "", [b, c])
2018-03-19 08:33:53 +01:00
od = OptionDescription('od', '', [descr])
2020-01-22 20:46:18 +01:00
async with await Config(od) as cfg_ori:
with pytest.raises(ConfigError):
await cfg_ori.option('int.str', 0).owner.set('user')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('int.int').value.set([0, 1])
await cfg.option('int.str', 0).value.set('yes')
assert not await cfg.option('int.str', 0).owner.isdefault()
assert await cfg.option('int.str', 1).owner.isdefault()
if config_type == 'tiramisu-api':
await cfg.send()
2019-12-24 15:24:20 +01:00
await cfg_ori.option('int.str', 0).owner.set('user')
2020-01-22 20:46:18 +01:00
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('int.str', 0).owner.get() == owners.user
assert await cfg.option('int.str', 1).owner.isdefault()
assert await cfg.option('int.str', 0).value.get() == 'yes'
assert await cfg.option('int.str', 1).value.get() == None
assert not await list_sessions()