tiramisu/test/test_config_ip.py

248 lines
6.8 KiB
Python
Raw Normal View History

2015-07-24 17:54:10 +02:00
from autopath import do_autopath
do_autopath()
import warnings
from py.test import raises
from tiramisu.config import Config
from tiramisu.option import IPOption, NetworkOption, NetmaskOption, \
2017-02-04 10:21:44 +01:00
PortOption, BroadcastOption, OptionDescription
from tiramisu.error import ValueWarning
def test_ip():
a = IPOption('a', '')
2013-09-27 11:28:23 +02:00
b = IPOption('b', '', private_only=True)
d = IPOption('d', '', warnings_only=True, private_only=True)
warnings.simplefilter("always", ValueWarning)
od = OptionDescription('od', '', [a, b, d])
c = Config(od)
c.a = '192.168.1.1'
c.a = '192.168.1.0'
c.a = '88.88.88.88'
c.a = '0.0.0.0'
2013-07-11 23:05:33 +02:00
raises(ValueError, "c.a = '255.255.255.0'")
c.b = '192.168.1.1'
c.b = '192.168.1.0'
2013-07-11 23:05:33 +02:00
raises(ValueError, "c.b = '88.88.88.88'")
c.b = '0.0.0.0'
2013-07-11 23:05:33 +02:00
raises(ValueError, "c.b = '255.255.255.0'")
2017-02-04 10:21:44 +01:00
raises(ValueError, "c.a = '333.0.1.20'")
2013-07-11 23:05:33 +02:00
raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')")
with warnings.catch_warnings(record=True) as w:
c.d = '88.88.88.88'
assert len(w) == 1
2013-07-11 23:05:33 +02:00
2015-07-24 17:54:10 +02:00
2013-07-11 23:05:33 +02:00
def test_ip_default():
a = IPOption('a', '', '88.88.88.88')
od = OptionDescription('od', '', [a])
c = Config(od)
c.a == '88.88.88.88'
2013-09-19 21:51:55 +02:00
def test_ip_reserved():
a = IPOption('a', '')
b = IPOption('b', '', allow_reserved=True)
c = IPOption('c', '', warnings_only=True)
od = OptionDescription('od', '', [a, b, c])
warnings.simplefilter("always", ValueWarning)
cfg = Config(od)
raises(ValueError, "cfg.a = '226.94.1.1'")
cfg.b = '226.94.1.1'
with warnings.catch_warnings(record=True) as w:
cfg.c = '226.94.1.1'
assert len(w) == 1
2013-09-19 21:51:55 +02:00
def test_network():
a = NetworkOption('a', '')
b = NetworkOption('b', '', warnings_only=True)
od = OptionDescription('od', '', [a, b])
warnings.simplefilter("always", ValueWarning)
c = Config(od)
c.a = '192.168.1.1'
c.a = '192.168.1.0'
c.a = '88.88.88.88'
c.a = '0.0.0.0'
2017-02-04 10:21:44 +01:00
raises(ValueError, "c.a = 1")
raises(ValueError, "c.a = '1.1.1.1.1'")
2013-07-11 23:05:33 +02:00
raises(ValueError, "c.a = '255.255.255.0'")
2017-02-04 10:21:44 +01:00
raises(ValueError, "c.a = '192.168.001.0'")
raises(ValueError, "c.a = '333.168.1.1'")
with warnings.catch_warnings(record=True) as w:
c.b = '255.255.255.0'
assert len(w) == 1
2013-07-11 23:05:33 +02:00
2016-01-03 21:18:52 +01:00
def test_network_invalid():
raises(ValueError, "NetworkOption('a', '', default='toto')")
def test_netmask():
a = NetmaskOption('a', '')
od = OptionDescription('od', '', [a])
c = Config(od)
2017-02-04 10:21:44 +01:00
raises(ValueError, "c.a = '192.168.1.1.1'")
2013-07-11 23:05:33 +02:00
raises(ValueError, "c.a = '192.168.1.1'")
raises(ValueError, "c.a = '192.168.1.0'")
raises(ValueError, "c.a = '88.88.88.88'")
2017-02-04 10:21:44 +01:00
raises(ValueError, "c.a = '255.255.255.000'")
raises(ValueError, "c.a = 2")
c.a = '0.0.0.0'
c.a = '255.255.255.0'
def test_broadcast():
a = BroadcastOption('a', '')
od = OptionDescription('od', '', [a])
c = Config(od)
raises(ValueError, "c.a = '192.168.1.255.1'")
raises(ValueError, "c.a = '192.168.001.255'")
raises(ValueError, "c.a = '192.168.0.300'")
raises(ValueError, "c.a = 1")
raises(ValueError, "c.a = 2")
c.a = '0.0.0.0'
c.a = '255.255.255.0'
2013-07-11 23:05:33 +02:00
def test_port():
a = PortOption('a', '')
b = PortOption('b', '', allow_zero=True)
c = PortOption('c', '', allow_zero=True, allow_registred=False)
d = PortOption('d', '', allow_zero=True, allow_wellknown=False, allow_registred=False)
e = PortOption('e', '', allow_zero=True, allow_private=True)
f = PortOption('f', '', allow_private=True)
od = OptionDescription('od', '', [a, b, c, d, e, f])
c = Config(od)
raises(ValueError, "c.a = 0")
c.a = 1
c.a = 1023
c.a = 1024
c.a = 49151
raises(ValueError, "c.a = 49152")
raises(ValueError, "c.a = 65535")
raises(ValueError, "c.a = 65536")
c.b = 0
c.b = 1
c.b = 1023
c.b = 1024
c.b = 49151
raises(ValueError, "c.b = 49152")
raises(ValueError, "c.b = 65535")
raises(ValueError, "c.b = 65536")
c.c = 0
c.c = 1
c.c = 1023
raises(ValueError, "c.c = 1024")
raises(ValueError, "c.c = 49151")
raises(ValueError, "c.c = 49152")
raises(ValueError, "c.c = 65535")
raises(ValueError, "c.c = 65536")
c.d = 0
raises(ValueError, "c.d = 1")
raises(ValueError, "c.d = 1023")
raises(ValueError, "c.d = 1024")
raises(ValueError, "c.d = 49151")
raises(ValueError, "c.d = 49152")
raises(ValueError, "c.d = 65535")
raises(ValueError, "c.d = 65536")
c.e = 0
c.e = 1
c.e = 1023
c.e = 1024
c.e = 49151
c.e = 49152
c.e = 65535
raises(ValueError, "c.f = 0")
c.f = 1
c.f = 1023
c.f = 1024
c.f = 49151
c.f = 49152
c.f = 65535
raises(ValueError, "c.f = 65536")
def test_port_range():
a = PortOption('a', '', allow_range=True)
b = PortOption('b', '', allow_range=True, allow_zero=True)
c = PortOption('c', '', allow_range=True, allow_zero=True, allow_registred=False)
d = PortOption('d', '', allow_range=True, allow_zero=True, allow_wellknown=False, allow_registred=False)
e = PortOption('e', '', allow_range=True, allow_zero=True, allow_private=True)
f = PortOption('f', '', allow_range=True, allow_private=True)
od = OptionDescription('od', '', [a, b, c, d, e, f])
c = Config(od)
raises(ValueError, "c.a = 0")
c.a = 1
c.a = 1023
c.a = 1024
c.a = 49151
raises(ValueError, "c.a = 49152")
raises(ValueError, "c.a = 65535")
raises(ValueError, "c.a = 65536")
c.a = '1:49151'
raises(ValueError, "c.a = '0:49151'")
raises(ValueError, "c.a = '1:49152'")
c.b = 0
c.b = 1
c.b = 1023
c.b = 1024
c.b = 49151
raises(ValueError, "c.b = 49152")
raises(ValueError, "c.b = 65535")
raises(ValueError, "c.b = 65536")
c.b = '0:49151'
raises(ValueError, "c.b = '0:49152'")
c.c = 0
c.c = 1
c.c = 1023
raises(ValueError, "c.c = 1024")
raises(ValueError, "c.c = 49151")
raises(ValueError, "c.c = 49152")
raises(ValueError, "c.c = 65535")
raises(ValueError, "c.c = 65536")
c.c = '0:1023'
raises(ValueError, "c.c = '0:1024'")
c.d = 0
raises(ValueError, "c.d = 1")
raises(ValueError, "c.d = 1023")
raises(ValueError, "c.d = 1024")
raises(ValueError, "c.d = 49151")
raises(ValueError, "c.d = 49152")
raises(ValueError, "c.d = 65535")
raises(ValueError, "c.d = 65536")
raises(ValueError, "c.d = '0:0'")
raises(ValueError, "c.d = '0:1'")
c.e = 0
c.e = 1
c.e = 1023
c.e = 1024
c.e = 49151
c.e = 49152
c.e = 65535
c.e = '0:65535'
raises(ValueError, "c.e = '0:65536'")
raises(ValueError, "c.f = 0")
c.f = 1
c.f = 1023
c.f = 1024
c.f = 49151
c.f = 49152
c.f = 65535
raises(ValueError, "c.f = 65536")
c.f = '1:65535'
c.f = '3:4'
raises(ValueError, "c.f = '0:65535'")
raises(ValueError, "c.f = '4:3'")