class TestUdpAddress(object):

    def setup(self):
        self.address = UdpAddress()
        self.address.low = 1
        self.address.high = 2

    def test_initialization(self):
        assert_equals(self.address.type, 'UDP')

    def test_repr(self):
        assert_equals(self.address.__repr__(), "<UdpAddress 1-2>")

    def test_str(self):
        assert_equals(self.address.__str__(), "UDP 1-2")

    def test_contains(self):
        udp_port = UdpAddress.from_string('1')
        udp_ports = UdpAddress.from_string('1-3')
        assert_in(udp_port, udp_ports)

    def test_not_contains(self):
        udp_port = UdpAddress.from_string('1')
        tcp_ports = TcpAddress.from_string('1-3')
        assert_not_in(udp_port, tcp_ports)
Exemple #2
0
 def test_from_string(self):
     layer = TransportLayerBuilder.build('tcp 1 2 3 4')
     assert_in(TcpAddress.from_string('1 2'), layer.source)
     assert_in(TcpAddress.from_string('3 4'), layer.destination)
     layer = TransportLayerBuilder.build('udp 1-2 3-4')
     assert_in(UdpAddress.from_string('1 2'), layer.source)
     assert_in(UdpAddress.from_string('3 4'), layer.destination)
     layer = TransportLayerBuilder.build('tcp 1-2 3 4')
     assert_in(TcpAddress.from_string('1 2'), layer.source)
     layer = TransportLayerBuilder.build('tcp 1 2')
     assert_in(TcpAddress.from_string('1'), layer.source)
     assert_in(TcpAddress.from_string('2'), layer.destination)
 def test_from_string(self):
     layer = TransportLayerBuilder.build('tcp 1 2 3 4')
     assert_in(TcpAddress.from_string('1 2'), layer.source)
     assert_in(TcpAddress.from_string('3 4'), layer.destination)
     layer = TransportLayerBuilder.build('udp 1-2 3-4')
     assert_in(UdpAddress.from_string('1 2'), layer.source)
     assert_in(UdpAddress.from_string('3 4'), layer.destination)
     layer = TransportLayerBuilder.build('tcp 1-2 3 4')
     assert_in(TcpAddress.from_string('1 2'), layer.source)
     layer = TransportLayerBuilder.build('tcp 1 2')
     assert_in(TcpAddress.from_string('1'), layer.source)
     assert_in(TcpAddress.from_string('2'), layer.destination)
 def test_not_contains(self):
     udp_port = UdpAddress.from_string('1')
     tcp_ports = TcpAddress.from_string('1-3')
     assert_not_in(udp_port, tcp_ports)
 def setup(self):
     self.address = UdpAddress()
     self.address.low = 1
     self.address.high = 2
 def test_not_contains(self):
     tcp_port = TcpAddress.from_string('1')
     udp_ports = UdpAddress.from_string('1-3')
     assert_not_in(tcp_port, udp_ports)
 def test_add_mixed_ports(self):
     group = TransportGroup()
     group.add(TransportAddress.from_string('1-3'))
     group.add(TcpAddress.from_string('1-3'))
     group.add(UdpAddress.from_string('1-3'))
     assert_equals(len(group), 3)
 def test_add_mixed_ports(self):
     group = TransportGroup()
     group.add(TransportAddress.from_string('1-3'))
     group.add(TcpAddress.from_string('1-3'))
     group.add(UdpAddress.from_string('1-3'))
     assert_equals(len(group), 3)