Skip to content

Commit

Permalink
Add tests for source_ip and source_port
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceaulinic committed Feb 1, 2017
1 parent 9cec2f7 commit fab3b14
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tornado/test/tcpclient_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ def skipIfLocalhostV4(self):
self.skipTest("localhost does not resolve to ipv6")

@gen_test
def do_test_connect(self, family, host):
def do_test_connect(self, family, host, source_ip=None, source_port=None):
port = self.start_server(family)
stream = yield self.client.connect(host, port)
stream = yield self.client.connect(host, port,
source_ip=source_ip,
source_port=source_port)
with closing(stream):
stream.write(b"hello")
data = yield self.server.streams[0].read_bytes(5)
Expand Down Expand Up @@ -125,6 +127,32 @@ def test_refused_ipv4(self):
with self.assertRaises(IOError):
yield self.client.connect('127.0.0.1', port)

def test_source_ip_fail(self):
'''
Fail when trying to use the source IP Address '8.8.8.8'.
'''
self.assertRaises(socket.error,
self.do_test_connect,
socket.AF_INET,
'127.0.0.1',
source_ip='8.8.8.8')

def test_source_ip_success(self):
'''
Success when trying to use the source IP Address '127.0.0.1'
'''
self.do_test_connect(socket.AF_INET, '127.0.0.1', source_ip='127.0.0.1')

def test_source_port_fail(self):
'''
Fail when trying to use source port 1.
'''
self.assertRaises(socket.error,
self.do_test_connect,
socket.AF_INET,
'127.0.0.1',
source_port=1)


class TestConnectorSplit(unittest.TestCase):
def test_one_family(self):
Expand Down

0 comments on commit fab3b14

Please sign in to comment.