async version of tiramisu
This commit is contained in:
@ -3,7 +3,7 @@ do_autopath()
|
||||
from .config import config_type, get_config, value_list, global_owner
|
||||
|
||||
import warnings, sys
|
||||
from py.test import raises
|
||||
import pytest
|
||||
|
||||
from tiramisu import Config, DomainnameOption, EmailOption, URLOption, OptionDescription
|
||||
from tiramisu.error import ValueWarning
|
||||
@ -15,65 +15,78 @@ def teardown_function(function):
|
||||
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
||||
|
||||
|
||||
def test_domainname(config_type):
|
||||
@pytest.mark.asyncio
|
||||
async def test_domainname(config_type):
|
||||
d = DomainnameOption('d', '')
|
||||
f = DomainnameOption('f', '', allow_without_dot=True)
|
||||
g = DomainnameOption('g', '', allow_ip=True)
|
||||
h = DomainnameOption('h', '', allow_cidr_network=True)
|
||||
od = OptionDescription('a', '', [d, f, g, h])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg = await Config(od)
|
||||
await cfg.property.read_write()
|
||||
cfg = await get_config(cfg, config_type)
|
||||
#
|
||||
cfg.option('d').value.set('toto.com')
|
||||
raises(ValueError, "cfg.option('d').value.set('toto')")
|
||||
cfg.option('d').value.set('toto3.com')
|
||||
raises(ValueError, "cfg.option('d').value.set('toto_super.com')")
|
||||
cfg.option('d').value.set('toto-.com')
|
||||
raises(ValueError, "cfg.option('d').value.set('toto..com')")
|
||||
await cfg.option('d').value.set('toto.com')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('d').value.set('toto')
|
||||
await cfg.option('d').value.set('toto3.com')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('d').value.set('toto_super.com')
|
||||
await cfg.option('d').value.set('toto-.com')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('d').value.set('toto..com')
|
||||
#
|
||||
cfg.option('f').value.set('toto.com')
|
||||
cfg.option('f').value.set('toto')
|
||||
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
||||
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
|
||||
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
||||
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
||||
raises(ValueError, "cfg.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')")
|
||||
cfg.option('f').value.set('d')
|
||||
cfg.option('f').value.set('d.t')
|
||||
await cfg.option('f').value.set('toto.com')
|
||||
await cfg.option('f').value.set('toto')
|
||||
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')
|
||||
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
||||
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')
|
||||
await cfg.option('f').value.set('d')
|
||||
await cfg.option('f').value.set('d.t')
|
||||
#
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
raises(ValueError, "cfg.option('f').value.set('192.168.1.1')")
|
||||
raises(ValueError, "cfg.option('f').value.set('192.168.1.0/24')")
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('f').value.set('192.168.1.1')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('f').value.set('192.168.1.0/24')
|
||||
#
|
||||
cfg.option('g').value.set('toto.com')
|
||||
cfg.option('g').value.set('192.168.1.0')
|
||||
cfg.option('g').value.set('192.168.1.29')
|
||||
raises(ValueError, "cfg.option('g').value.set('192.168.1.0/24')")
|
||||
await cfg.option('g').value.set('toto.com')
|
||||
await cfg.option('g').value.set('192.168.1.0')
|
||||
await cfg.option('g').value.set('192.168.1.29')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('g').value.set('192.168.1.0/24')
|
||||
#
|
||||
cfg.option('h').value.set('toto.com')
|
||||
await cfg.option('h').value.set('toto.com')
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
raises(ValueError, "cfg.option('h').value.set('192.168.1.0')")
|
||||
raises(ValueError, "cfg.option('h').value.set('192.168.1.29')")
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('h').value.set('192.168.1.0')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('h').value.set('192.168.1.29')
|
||||
# it's a network address
|
||||
cfg.option('h').value.set('192.168.1.0/24')
|
||||
await cfg.option('h').value.set('192.168.1.0/24')
|
||||
# but not here
|
||||
raises(ValueError, "cfg.option('h').value.set('192.168.1.1/24')")
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('h').value.set('192.168.1.1/24')
|
||||
|
||||
|
||||
def test_domainname_upper(config_type):
|
||||
@pytest.mark.asyncio
|
||||
async def test_domainname_upper(config_type):
|
||||
d = DomainnameOption('d', '')
|
||||
od = OptionDescription('a', '', [d])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('d').value.set('toto.com')
|
||||
cfg = await Config(od)
|
||||
await cfg.property.read_write()
|
||||
cfg = await get_config(cfg, config_type)
|
||||
await cfg.option('d').value.set('toto.com')
|
||||
msg = _('some characters are uppercase')
|
||||
has_error = False
|
||||
try:
|
||||
cfg.option('d').value.set('TOTO.COM')
|
||||
await cfg.option('d').value.set('TOTO.COM')
|
||||
except ValueError as err:
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
@ -82,7 +95,7 @@ def test_domainname_upper(config_type):
|
||||
assert has_error is True
|
||||
has_error = False
|
||||
try:
|
||||
cfg.option('d').value.set('toTo.com')
|
||||
await cfg.option('d').value.set('toTo.com')
|
||||
except ValueError as err:
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
@ -91,129 +104,154 @@ def test_domainname_upper(config_type):
|
||||
assert has_error is True
|
||||
|
||||
|
||||
def test_domainname_warning(config_type):
|
||||
@pytest.mark.asyncio
|
||||
async def test_domainname_warning(config_type):
|
||||
d = DomainnameOption('d', '', warnings_only=True)
|
||||
f = DomainnameOption('f', '', allow_without_dot=True, warnings_only=True)
|
||||
g = DomainnameOption('g', '', allow_ip=True, warnings_only=True)
|
||||
od = OptionDescription('a', '', [d, f, g])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('d').value.set('toto.com')
|
||||
raises(ValueError, "cfg.option('d').value.set('toto')")
|
||||
cfg.option('d').value.set('toto3.com')
|
||||
cfg = await Config(od)
|
||||
await cfg.property.read_write()
|
||||
cfg = await get_config(cfg, config_type)
|
||||
await cfg.option('d').value.set('toto.com')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('d').value.set('toto')
|
||||
await cfg.option('d').value.set('toto3.com')
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.option('d').value.set('toto_super.com')
|
||||
await cfg.option('d').value.set('toto_super.com')
|
||||
assert len(w) == 1
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
cfg.option('d').value.set('toto-.com')
|
||||
await cfg.option('d').value.set('toto-.com')
|
||||
assert len(w) == 0
|
||||
raises(ValueError, "cfg.option('d').value.set('toto..com')")
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('d').value.set('toto..com')
|
||||
#
|
||||
cfg.option('f').value.set('toto.com')
|
||||
cfg.option('f').value.set('toto')
|
||||
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
||||
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
|
||||
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
||||
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
||||
await cfg.option('f').value.set('toto.com')
|
||||
await cfg.option('f').value.set('toto')
|
||||
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')
|
||||
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
||||
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')")
|
||||
cfg.option('f').value.set('d')
|
||||
cfg.option('f').value.set('d.t')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')
|
||||
await cfg.option('f').value.set('d')
|
||||
await cfg.option('f').value.set('d.t')
|
||||
#
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
raises(ValueError, "cfg.option('f').value.set('192.168.1.1')")
|
||||
cfg.option('g').value.set('toto.com')
|
||||
cfg.option('g').value.set('192.168.1.0')
|
||||
cfg.option('g').value.set('192.168.1.29')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('f').value.set('192.168.1.1')
|
||||
await cfg.option('g').value.set('toto.com')
|
||||
await cfg.option('g').value.set('192.168.1.0')
|
||||
await cfg.option('g').value.set('192.168.1.29')
|
||||
|
||||
|
||||
def test_special_domain_name(config_type):
|
||||
@pytest.mark.asyncio
|
||||
async def test_special_domain_name(config_type):
|
||||
"""domain name option that starts with a number or not
|
||||
"""
|
||||
d = DomainnameOption('d', '')
|
||||
e = DomainnameOption('e', '', type='netbios')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('d').value.set('1toto.com')
|
||||
cfg.option('d').value.set('123toto.com')
|
||||
cfg.option('e').value.set('toto')
|
||||
cfg.option('e').value.set('1toto')
|
||||
cfg = await Config(od)
|
||||
await cfg.property.read_write()
|
||||
cfg = await get_config(cfg, config_type)
|
||||
await cfg.option('d').value.set('1toto.com')
|
||||
await cfg.option('d').value.set('123toto.com')
|
||||
await cfg.option('e').value.set('toto')
|
||||
await cfg.option('e').value.set('1toto')
|
||||
|
||||
|
||||
def test_domainname_netbios(config_type):
|
||||
@pytest.mark.asyncio
|
||||
async def test_domainname_netbios(config_type):
|
||||
d = DomainnameOption('d', '', type='netbios')
|
||||
e = DomainnameOption('e', '', "toto", type='netbios')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
raises(ValueError, "cfg.option('d').value.set('toto.com')")
|
||||
cfg.option('d').value.set('toto')
|
||||
raises(ValueError, "cfg.option('d').value.set('domainnametoolong')")
|
||||
cfg = await Config(od)
|
||||
await cfg.property.read_write()
|
||||
cfg = await get_config(cfg, config_type)
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('d').value.set('toto.com')
|
||||
await cfg.option('d').value.set('toto')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('d').value.set('domainnametoolong')
|
||||
|
||||
|
||||
def test_domainname_hostname(config_type):
|
||||
@pytest.mark.asyncio
|
||||
async def test_domainname_hostname(config_type):
|
||||
d = DomainnameOption('d', '', type='hostname')
|
||||
e = DomainnameOption('e', '', "toto", type='hostname')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
raises(ValueError, "cfg.option('d').value.set('toto.com')")
|
||||
cfg.option('d').value.set('toto')
|
||||
cfg.option('d').value.set('domainnametoolong')
|
||||
cfg = await Config(od)
|
||||
await cfg.property.read_write()
|
||||
cfg = await get_config(cfg, config_type)
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('d').value.set('toto.com')
|
||||
await cfg.option('d').value.set('toto')
|
||||
await cfg.option('d').value.set('domainnametoolong')
|
||||
|
||||
|
||||
def test_email(config_type):
|
||||
@pytest.mark.asyncio
|
||||
async def test_email(config_type):
|
||||
e = EmailOption('e', '')
|
||||
od = OptionDescription('a', '', [e])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('e').value.set('foo-bar.baz@example.com')
|
||||
cfg.option('e').value.set('root@foo.com')
|
||||
cfg.option('e').value.set('root@domain')
|
||||
raises(ValueError, "cfg.option('e').value.set(1)")
|
||||
raises(ValueError, "cfg.option('e').value.set('root')")
|
||||
raises(ValueError, "cfg.option('e').value.set('root[]@domain')")
|
||||
cfg = await Config(od)
|
||||
await cfg.property.read_write()
|
||||
cfg = await get_config(cfg, config_type)
|
||||
await cfg.option('e').value.set('foo-bar.baz@example.com')
|
||||
await cfg.option('e').value.set('root@foo.com')
|
||||
await cfg.option('e').value.set('root@domain')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('e').value.set(1)
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('e').value.set('root')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('e').value.set('root[]@domain')
|
||||
|
||||
|
||||
def test_url(config_type):
|
||||
@pytest.mark.asyncio
|
||||
async def test_url(config_type):
|
||||
u = URLOption('u', '')
|
||||
od = OptionDescription('a', '', [u])
|
||||
cfg = Config(od)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('u').value.set('http://foo.com')
|
||||
cfg.option('u').value.set('https://foo.com')
|
||||
cfg.option('u').value.set('https://foo.com/')
|
||||
raises(ValueError, "cfg.option('u').value.set(1)")
|
||||
cfg = await Config(od)
|
||||
await cfg.property.read_write()
|
||||
cfg = await get_config(cfg, config_type)
|
||||
await cfg.option('u').value.set('http://foo.com')
|
||||
await cfg.option('u').value.set('https://foo.com')
|
||||
await cfg.option('u').value.set('https://foo.com/')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('u').value.set(1)
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
raises(ValueError, "cfg.option('u').value.set('ftp://foo.com')")
|
||||
raises(ValueError, "cfg.option('u').value.set('foo.com')")
|
||||
raises(ValueError, "cfg.option('u').value.set(':/foo.com')")
|
||||
raises(ValueError, "cfg.option('u').value.set('foo.com/http://')")
|
||||
cfg.option('u').value.set('https://foo.com/index.html')
|
||||
cfg.option('u').value.set('https://foo.com/index.html?var=value&var2=val2')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('u').value.set('ftp://foo.com')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('u').value.set('foo.com')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('u').value.set(':/foo.com')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('u').value.set('foo.com/http://')
|
||||
await cfg.option('u').value.set('https://foo.com/index.html')
|
||||
await cfg.option('u').value.set('https://foo.com/index.html?var=value&var2=val2')
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
raises(ValueError, "cfg.option('u').value.set('https://foo.com/index\\n.html')")
|
||||
cfg.option('u').value.set('https://foo.com:8443')
|
||||
cfg.option('u').value.set('https://foo.com:8443/')
|
||||
cfg.option('u').value.set('https://foo.com:8443/index.html')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('u').value.set('https://foo.com/index\\n.html')
|
||||
await cfg.option('u').value.set('https://foo.com:8443')
|
||||
await cfg.option('u').value.set('https://foo.com:8443/')
|
||||
await cfg.option('u').value.set('https://foo.com:8443/index.html')
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
raises(ValueError, "cfg.option('u').value.set('https://foo.com:84438989')")
|
||||
cfg.option('u').value.set('https://foo.com:8443/INDEX')
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('u').value.set('https://foo.com:84438989')
|
||||
await cfg.option('u').value.set('https://foo.com:8443/INDEX')
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME
|
||||
raises(ValueError, "cfg.option('u').value.set('https://FOO.COM:8443')")
|
||||
with pytest.raises(ValueError):
|
||||
await cfg.option('u').value.set('https://FOO.COM:8443')
|
||||
|
Reference in New Issue
Block a user