tiramisu/test/test_requires.py

134 lines
3.8 KiB
Python
Raw Normal View History

# coding: utf-8
import autopath
from tiramisu import setting
setting.expires_time = 1
from tiramisu.option import IPOption, OptionDescription, BoolOption
from tiramisu.config import Config
from tiramisu.error import PropertiesOptionError, RequirementError
from py.test import raises
def test_requires():
a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '',
requires=[(a, False, 'disabled')])
od = OptionDescription('service', '', [a, b])
c = Config(od)
c.read_write()
c.ip_address_service
c.activate_service = False
props = []
try:
c.ip_address_service
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
2013-06-10 15:19:00 +02:00
def test_requires_transitive():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'disabled')])
2013-06-10 15:19:00 +02:00
d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled')])
od = OptionDescription('service', '', [a, b, d])
c = Config(od)
c.read_write()
c.activate_service
c.activate_service_web
c.ip_address_service_web
c.activate_service = False
#
props = []
try:
c.activate_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
#
props = []
try:
c.ip_address_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
2013-06-10 15:19:00 +02:00
def test_requires_transitive_bis():
a = BoolOption('activate_service', '', True)
abis = BoolOption('activate_service_bis', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, True, 'disabled', True)])
d = IPOption('ip_address_service_web', '',
requires=[(b, True, 'disabled', True)])
od = OptionDescription('service', '', [a, abis, b, d])
c = Config(od)
c.read_write()
#
c.activate_service_web
c.ip_address_service_web
c.activate_service = False
#
props = []
try:
c.activate_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
#
props = []
try:
c.ip_address_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
def test_requires_transitive_hidden_disabled():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'hidden')])
d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled')])
od = OptionDescription('service', '', [a, b, d])
c = Config(od)
c.read_write()
c.activate_service
c.activate_service_web
c.ip_address_service_web
c.activate_service = False
#
props = []
try:
c.activate_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['hidden']
raises(RequirementError, 'c.ip_address_service_web')
2013-06-10 15:19:00 +02:00
def test_requires_not_transitive():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[(a, False, 'disabled')])
d = IPOption('ip_address_service_web', '',
requires=[(b, False, 'disabled', False, False)])
od = OptionDescription('service', '', [a, b, d])
c = Config(od)
c.read_write()
c.activate_service
c.activate_service_web
c.ip_address_service_web
c.activate_service = False
#
props = []
try:
c.activate_service_web
except PropertiesOptionError, err:
props = err.proptype
assert props == ['disabled']
#
c.ip_address_service_web