2013-05-08 18:14:42 +02:00
|
|
|
import autopath
|
|
|
|
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
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_domainname():
|
|
|
|
d = DomainnameOption('d', '')
|
2013-05-10 09:27:54 +02:00
|
|
|
e = DomainnameOption('e', '', "toto.com")
|
|
|
|
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
|
|
|
c.d = 'toto.com'
|
|
|
|
raises(ValueError, "c.d = 'toto'")
|
|
|
|
c.d = 'toto3.com'
|
2013-09-30 19:41:56 +02:00
|
|
|
raises(ValueError, "c.d = 'toto3.3la'")
|
2013-05-08 18:14:42 +02:00
|
|
|
raises(ValueError, "c.d = '3toto.com'")
|
2013-09-30 19:41:56 +02:00
|
|
|
raises(ValueError, "c.d = 'toto.co3'")
|
2013-05-08 18:14:42 +02:00
|
|
|
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-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'")
|
|
|
|
|
|
|
|
|
|
|
|
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'
|