2015-07-24 17:54:10 +02:00
|
|
|
from autopath import do_autopath
|
|
|
|
do_autopath()
|
|
|
|
|
2014-10-26 09:38:17 +01:00
|
|
|
import warnings
|
2013-05-08 18:14:42 +02:00
|
|
|
from py.test import raises
|
|
|
|
|
|
|
|
from tiramisu.config import Config
|
2013-09-30 19:41:56 +02:00
|
|
|
from tiramisu.option import DomainnameOption, EmailOption, URLOption, OptionDescription
|
2014-10-26 09:38:17 +01:00
|
|
|
from tiramisu.error import ValueWarning
|
2014-12-07 14:51:51 +01:00
|
|
|
from tiramisu.i18n import _
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
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])
|
2013-05-08 18:14:42 +02:00
|
|
|
c = Config(od)
|
2013-05-10 22:32:42 +02:00
|
|
|
c.read_write()
|
2013-05-08 18:14:42 +02:00
|
|
|
c.d = 'toto.com'
|
|
|
|
raises(ValueError, "c.d = 'toto'")
|
|
|
|
c.d = 'toto3.com'
|
|
|
|
raises(ValueError, "c.d = 'toto_super.com'")
|
|
|
|
c.d = 'toto-.com'
|
2013-09-30 19:41:56 +02:00
|
|
|
raises(ValueError, "c.d = 'toto..com'")
|
2013-10-01 10:13:17 +02:00
|
|
|
#
|
|
|
|
c.f = 'toto.com'
|
|
|
|
c.f = 'toto'
|
2014-10-26 09:38:17 +01:00
|
|
|
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea'
|
|
|
|
raises(ValueError, "c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean'")
|
|
|
|
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd'
|
|
|
|
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie'
|
|
|
|
raises(ValueError, "c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien'")
|
2014-02-06 22:17:20 +01:00
|
|
|
raises(ValueError, "c.f = 'd'")
|
2014-10-26 09:38:17 +01:00
|
|
|
raises(ValueError, "c.f = 'd.t'")
|
2014-02-06 22:17:20 +01:00
|
|
|
#
|
|
|
|
c.g = 'toto.com'
|
|
|
|
c.g = '192.168.1.0'
|
|
|
|
c.g = '192.168.1.29'
|
2013-05-08 18:14:42 +02:00
|
|
|
|
2014-10-26 09:38:17 +01:00
|
|
|
|
2014-12-07 14:51:51 +01:00
|
|
|
def test_domainname_upper():
|
|
|
|
d = DomainnameOption('d', '')
|
|
|
|
od = OptionDescription('a', '', [d])
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.d = 'toto.com'
|
|
|
|
msg = _('some characters are uppercase')
|
|
|
|
has_error = False
|
|
|
|
try:
|
|
|
|
c.d = 'TOTO.COM'
|
|
|
|
except ValueError, err:
|
|
|
|
assert msg in unicode(err)
|
|
|
|
has_error = True
|
|
|
|
assert has_error is True
|
|
|
|
has_error = False
|
|
|
|
try:
|
|
|
|
c.d = 'toTo.com'
|
|
|
|
except ValueError, err:
|
|
|
|
assert msg in unicode(err)
|
|
|
|
has_error = True
|
|
|
|
assert has_error is True
|
|
|
|
|
|
|
|
|
2014-10-26 09:38:17 +01:00
|
|
|
def test_domainname_warning():
|
|
|
|
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)
|
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.d = 'toto.com'
|
|
|
|
raises(ValueError, "c.d = 'toto'")
|
|
|
|
c.d = 'toto3.com'
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
|
|
|
c.d = 'toto_super.com'
|
|
|
|
assert len(w) == 1
|
|
|
|
c.d = 'toto-.com'
|
|
|
|
raises(ValueError, "c.d = 'toto..com'")
|
|
|
|
#
|
|
|
|
c.f = 'toto.com'
|
|
|
|
c.f = 'toto'
|
|
|
|
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea'
|
|
|
|
raises(ValueError, "c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean'")
|
|
|
|
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd'
|
|
|
|
c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie'
|
|
|
|
raises(ValueError, "c.f = 'domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien'")
|
|
|
|
raises(ValueError, "c.f = 'd'")
|
|
|
|
raises(ValueError, "c.f = 'd.t'")
|
|
|
|
#
|
|
|
|
c.g = 'toto.com'
|
|
|
|
c.g = '192.168.1.0'
|
|
|
|
c.g = '192.168.1.29'
|
|
|
|
|
|
|
|
|
2014-02-25 15:20:03 +01:00
|
|
|
def test_special_domain_name():
|
|
|
|
"""domain name option that starts with a number or not
|
2014-02-25 14:19:54 +01:00
|
|
|
"""
|
|
|
|
d = DomainnameOption('d', '')
|
2014-02-25 15:20:03 +01:00
|
|
|
e = DomainnameOption('e', '', type_='netbios')
|
2014-10-26 09:38:17 +01:00
|
|
|
od = OptionDescription('a', '', [d, e])
|
2014-02-25 14:19:54 +01:00
|
|
|
c = Config(od)
|
|
|
|
c.read_write()
|
|
|
|
c.d = '1toto.com'
|
|
|
|
c.d = '123toto.com'
|
2014-02-25 15:20:03 +01:00
|
|
|
c.e = 'toto'
|
2014-10-25 22:58:46 +02:00
|
|
|
c.e = '1toto'
|
2014-02-25 15:20:03 +01:00
|
|
|
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
def test_domainname_netbios():
|
|
|
|
d = DomainnameOption('d', '', type_='netbios')
|
2013-05-10 09:27:54 +02:00
|
|
|
e = DomainnameOption('e', '', "toto", type_='netbios')
|
|
|
|
od = OptionDescription('a', '', [d, e])
|
2013-05-08 18:14:42 +02:00
|
|
|
c = Config(od)
|
2013-05-10 22:32:42 +02:00
|
|
|
c.read_write()
|
2013-05-08 18:14:42 +02:00
|
|
|
raises(ValueError, "c.d = 'toto.com'")
|
|
|
|
c.d = 'toto'
|
|
|
|
raises(ValueError, "c.d = 'domainnametoolong'")
|
|
|
|
|
|
|
|
|
|
|
|
def test_domainname_hostname():
|
|
|
|
d = DomainnameOption('d', '', type_='hostname')
|
2013-05-10 09:27:54 +02:00
|
|
|
e = DomainnameOption('e', '', "toto", type_='hostname')
|
|
|
|
od = OptionDescription('a', '', [d, e])
|
2013-05-08 18:14:42 +02:00
|
|
|
c = Config(od)
|
2013-05-10 22:32:42 +02:00
|
|
|
c.read_write()
|
2013-05-08 18:14:42 +02:00
|
|
|
raises(ValueError, "c.d = 'toto.com'")
|
|
|
|
c.d = 'toto'
|
|
|
|
c.d = 'domainnametoolong'
|
2013-09-30 19:41:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
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'")
|
2013-09-30 19:41:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
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://'")
|
2013-09-30 19:41:56 +02:00
|
|
|
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'")
|
2015-04-19 09:46:39 +02:00
|
|
|
c.u = 'https://foo.com:8443/INDEX'
|
|
|
|
raises(ValueError, "c.u = 'https://FOO.COM:8443'")
|