tiramisu/test/test_storage.py

154 lines
4.7 KiB
Python
Raw Normal View History

# coding: utf-8
2015-07-24 17:54:10 +02:00
from autopath import do_autopath
do_autopath()
2013-08-27 09:46:52 +02:00
#from py.test import raises
from tiramisu.config import Config
from tiramisu.option import BoolOption, OptionDescription
2013-08-27 22:08:35 +02:00
from tiramisu.setting import owners
from tiramisu.storage import list_sessions, delete_session
2013-08-27 09:46:52 +02:00
def test_non_persistent():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
Config(o, session_id='test_non_persistent')
def test_list():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o, session_id='test_non_persistent')
2013-09-07 17:25:22 +02:00
c.cfgimpl_get_settings().remove('cache')
2014-04-12 22:47:52 +02:00
assert 'test_non_persistent' in list_sessions('config')
2013-08-27 09:46:52 +02:00
del(c)
2014-04-12 22:47:52 +02:00
assert 'test_non_persistent' not in list_sessions('config')
2013-08-27 09:46:52 +02:00
def test_create_persistent():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
try:
Config(o, session_id='test_persistent', persistent=True)
except ValueError:
# storage is not persistent
pass
def test_list_sessions_persistent():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
try:
Config(o, session_id='test_persistent', persistent=True)
except ValueError:
# storage is not persistent
pass
else:
2014-04-12 22:47:52 +02:00
assert 'test_persistent' in list_sessions('config')
2013-08-27 09:46:52 +02:00
def test_delete_session_persistent():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
try:
Config(o, session_id='test_persistent', persistent=True)
except ValueError:
# storage is not persistent
pass
else:
2014-04-12 22:47:52 +02:00
assert 'test_persistent' in list_sessions('config')
2013-08-27 09:46:52 +02:00
delete_session('test_persistent')
2014-04-12 22:47:52 +02:00
assert 'test_persistent' not in list_sessions('config')
2013-08-27 09:46:52 +02:00
def test_create_persistent_retrieve():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
try:
c = Config(o, session_id='test_persistent', persistent=True)
2013-09-07 17:25:22 +02:00
c.cfgimpl_get_settings().remove('cache')
2013-08-27 09:46:52 +02:00
except ValueError:
# storage is not persistent
pass
else:
assert c.b is None
2013-08-27 09:46:52 +02:00
c.b = True
assert c.b is True
del(c)
c = Config(o, session_id='test_persistent', persistent=True)
2013-09-07 17:25:22 +02:00
c.cfgimpl_get_settings().remove('cache')
2013-08-27 09:46:52 +02:00
assert c.b is True
2014-04-12 22:47:52 +02:00
assert 'test_persistent' in list_sessions('config')
2013-08-27 09:46:52 +02:00
delete_session('test_persistent')
c = Config(o, session_id='test_persistent', persistent=True)
2013-09-07 17:25:22 +02:00
c.cfgimpl_get_settings().remove('cache')
assert c.b is None
2013-08-27 22:08:35 +02:00
delete_session('test_persistent')
2013-08-27 22:08:35 +02:00
def test_two_persistent():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
try:
c = Config(o, session_id='test_persistent', persistent=True)
2013-09-07 17:25:22 +02:00
c.cfgimpl_get_settings().remove('cache')
2013-08-27 22:08:35 +02:00
except ValueError:
# storage is not persistent
pass
else:
c2 = Config(o, session_id='test_persistent', persistent=True)
2013-09-07 17:25:22 +02:00
c2.cfgimpl_get_settings().remove('cache')
2013-08-27 22:08:35 +02:00
assert c.b is None
assert c2.b is None
c.b = False
assert c.b is False
assert c2.b is False
c.b = True
assert c.b is True
assert c2.b is True
delete_session('test_persistent')
def test_two_persistent_owner():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
try:
c = Config(o, session_id='test_persistent', persistent=True)
2013-09-07 17:25:22 +02:00
c.cfgimpl_get_settings().remove('cache')
2013-08-27 22:08:35 +02:00
except ValueError:
# storage is not persistent
pass
else:
c2 = Config(o, session_id='test_persistent', persistent=True)
2013-09-07 17:25:22 +02:00
c2.cfgimpl_get_settings().remove('cache')
2013-08-27 22:08:35 +02:00
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
c.cfgimpl_get_values().setowner(b, owners.persistent)
assert c.getowner(b) == owners.persistent
assert c2.getowner(b) == owners.persistent
delete_session('test_persistent')
def test_two_persistent_information():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
try:
c = Config(o, session_id='test_persistent', persistent=True)
2013-09-07 17:25:22 +02:00
c.cfgimpl_get_settings().remove('cache')
except ValueError:
# storage is not persistent
pass
else:
c.impl_set_information('info', 'string')
assert c.impl_get_information('info') == 'string'
c2 = Config(o, session_id='test_persistent', persistent=True)
2013-09-07 17:25:22 +02:00
c2.cfgimpl_get_settings().remove('cache')
c2.cfgimpl_get_settings().remove('cache')
assert c2.impl_get_information('info') == 'string'
delete_session('test_persistent')