add tests for persistent mode

This commit is contained in:
Emmanuel Garette 2013-08-27 22:08:35 +02:00
parent 3be005e82e
commit 71a8171c52
1 changed files with 45 additions and 3 deletions

View File

@ -4,6 +4,8 @@ import autopath
from tiramisu.config import Config
from tiramisu.option import BoolOption, OptionDescription
from tiramisu.setting import owners
from tiramisu.setting import list_sessions, delete_session
def test_non_persistent():
@ -54,7 +56,6 @@ def test_delete_session_persistent():
# storage is not persistent
pass
else:
from tiramisu.setting import list_sessions, delete_session
assert 'test_persistent' in list_sessions()
delete_session('test_persistent')
assert 'test_persistent' not in list_sessions()
@ -75,10 +76,51 @@ def test_create_persistent_retrieve():
del(c)
c = Config(o, session_id='test_persistent', persistent=True)
assert c.b is True
from tiramisu.setting import list_sessions, delete_session
assert 'test_persistent' in list_sessions()
delete_session('test_persistent')
c = Config(o, session_id='test_persistent', persistent=True)
assert c.b is None
delete_session('test_persistent')
#recup d'un coté de et l'autre
def test_two_persistent():
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:
c2 = Config(o, session_id='test_persistent', persistent=True)
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)
except ValueError:
# storage is not persistent
pass
else:
c2 = Config(o, session_id='test_persistent', persistent=True)
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')