tiramisu/test/test_requires.py

102 lines
2.9 KiB
Python

# 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']
def test_requires_transitif():
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')])
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']
def test_requires_transitif_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')
def test_requires_not_transitif():
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