tiramisu/test/test_config_domain.py

100 lines
3.1 KiB
Python
Raw Normal View History

import autopath
from py.test import raises
from tiramisu.config import Config
from tiramisu.option import DomainnameOption, EmailOption, URLOption, OptionDescription
def test_domainname():
d = DomainnameOption('d', '')
2013-10-01 10:13:17 +02:00
f = DomainnameOption('f', '', allow_without_dot=True)
2014-02-06 22:17:20 +01:00
g = DomainnameOption('g', '', allow_ip=True)
od = OptionDescription('a', '', [d, f, g])
c = Config(od)
2013-05-10 22:32:42 +02:00
c.read_write()
c.d = 'toto.com'
raises(ValueError, "c.d = 'toto'")
c.d = 'toto3.com'
raises(ValueError, "c.d = 'toto3.3la'")
#raises(ValueError, "c.d = '3toto.com'")
raises(ValueError, "c.d = 'toto.co3'")
raises(ValueError, "c.d = 'toto_super.com'")
c.d = 'toto-.com'
raises(ValueError, "c.d = 'toto..com'")
2013-10-01 10:13:17 +02:00
#
c.f = 'toto.com'
c.f = 'toto'
2014-02-06 22:17:20 +01:00
raises(ValueError, "c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnameanditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnametoolongthathavemorethanmaximumsizeforatruedomainnameanditsnoteasytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowiendityeah'")
raises(ValueError, "c.f = 'd'")
#
c.g = 'toto.com'
c.g = '192.168.1.0'
c.g = '192.168.1.29'
def test_special_domain_name():
"""domain name option that starts with a number or not
"""
d = DomainnameOption('d', '')
e = DomainnameOption('e', '', type_='netbios')
od = OptionDescription('a', '', [d,e])
c = Config(od)
c.read_write()
c.d = '1toto.com'
c.d = '123toto.com'
c.e = 'toto'
c.e = '1toto'
def test_domainname_netbios():
d = DomainnameOption('d', '', type_='netbios')
e = DomainnameOption('e', '', "toto", type_='netbios')
od = OptionDescription('a', '', [d, e])
c = Config(od)
2013-05-10 22:32:42 +02:00
c.read_write()
raises(ValueError, "c.d = 'toto.com'")
c.d = 'toto'
raises(ValueError, "c.d = 'domainnametoolong'")
def test_domainname_hostname():
d = DomainnameOption('d', '', type_='hostname')
e = DomainnameOption('e', '', "toto", type_='hostname')
od = OptionDescription('a', '', [d, e])
c = Config(od)
2013-05-10 22:32:42 +02:00
c.read_write()
raises(ValueError, "c.d = 'toto.com'")
c.d = 'toto'
c.d = 'domainnametoolong'
def test_email():
e = EmailOption('e', '')
od = OptionDescription('a', '', [e])
c = Config(od)
c.read_write()
c.e = 'root@foo.com'
raises(ValueError, "c.e = 'root'")
raises(ValueError, "c.e = 'root@domain'")
2014-02-06 22:17:20 +01:00
raises(ValueError, "c.e = 'root[]@domain'")
def test_url():
u = URLOption('u', '')
od = OptionDescription('a', '', [u])
c = Config(od)
c.read_write()
c.u = 'http://foo.com'
c.u = 'https://foo.com'
c.u = 'https://foo.com/'
raises(ValueError, "c.u = 'ftp://foo.com'")
2013-10-01 08:23:10 +02:00
raises(ValueError, "c.u = 'foo.com'")
raises(ValueError, "c.u = ':/foo.com'")
raises(ValueError, "c.u = 'foo.com/http://'")
c.u = 'https://foo.com/index.html'
c.u = 'https://foo.com/index.html?var=value&var2=val2'
raises(ValueError, "c.u = 'https://foo.com/index\\n.html'")
c.u = 'https://foo.com:8443'
c.u = 'https://foo.com:8443/'
c.u = 'https://foo.com:8443/index.html'
2014-02-06 22:17:20 +01:00
raises(ValueError, "c.u = 'https://foo.com:84438989'")