Commit 7c56771f authored by zhifan huang's avatar zhifan huang

chore: reformat code, rmove trailing space

parent 2d99db22
...@@ -21,7 +21,6 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -21,7 +21,6 @@ class testBaseTunnelManager(unittest.TestCase):
cls.cert = x509.Cert("ca.cert", "node.key", "node.cert") cls.cert = x509.Cert("ca.cert", "node.key", "node.cert")
cls.control_socket = "babeld.sock" cls.control_socket = "babeld.sock"
def setUp(self): def setUp(self):
patcher = patch("re6st.cache.Cache") patcher = patch("re6st.cache.Cache")
pacher_sock = patch("socket.socket") pacher_sock = patch("socket.socket")
...@@ -32,14 +31,13 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -32,14 +31,13 @@ class testBaseTunnelManager(unittest.TestCase):
self.cache.same_country = False self.cache.same_country = False
address = [(2, [('10.0.0.2', '1194', 'udp'), ('10.0.0.2', '1194', 'tcp')])] address = [(2, [('10.0.0.2', '1194', 'udp'), ('10.0.0.2', '1194', 'tcp')])]
self.tunnel = tunnel.BaseTunnelManager(self.control_socket, self.tunnel = tunnel.BaseTunnelManager(self.control_socket,
self.cache, self.cert, None, address) self.cache, self.cert, None, address)
def tearDown(self): def tearDown(self):
self.tunnel.close() self.tunnel.close()
del self.tunnel del self.tunnel
@patch("re6st.tunnel.BaseTunnelManager._babel_dump_one", create=True) @patch("re6st.tunnel.BaseTunnelManager._babel_dump_one", create=True)
@patch("re6st.tunnel.BaseTunnelManager._babel_dump_two", create=True) @patch("re6st.tunnel.BaseTunnelManager._babel_dump_two", create=True)
def test_babel_dump(self, two, one): def test_babel_dump(self, two, one):
...@@ -53,8 +51,6 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -53,8 +51,6 @@ class testBaseTunnelManager(unittest.TestCase):
one.assert_called_once() one.assert_called_once()
two.assert_called_once() two.assert_called_once()
@patch("re6st.ctl.Babel.request_dump") @patch("re6st.ctl.Babel.request_dump")
def test_request_dump_empty(self, request_dump): def test_request_dump_empty(self, request_dump):
"""case when self.__requesting_dump is None or empty""" """case when self.__requesting_dump is None or empty"""
...@@ -65,7 +61,6 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -65,7 +61,6 @@ class testBaseTunnelManager(unittest.TestCase):
self.assertEqual(self.tunnel._BaseTunnelManager__requesting_dump, set([reason])) self.assertEqual(self.tunnel._BaseTunnelManager__requesting_dump, set([reason]))
request_dump.assert_called_once() request_dump.assert_called_once()
@patch("re6st.ctl.Babel.request_dump") @patch("re6st.ctl.Babel.request_dump")
def test___request_dump_not_empty(self, request_dump): def test___request_dump_not_empty(self, request_dump):
"""case when self.__requesting_dump is not empty""" """case when self.__requesting_dump is not empty"""
...@@ -77,7 +72,6 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -77,7 +72,6 @@ class testBaseTunnelManager(unittest.TestCase):
self.assertEqual(self.tunnel._BaseTunnelManager__requesting_dump, set([reason, "rina"])) self.assertEqual(self.tunnel._BaseTunnelManager__requesting_dump, set([reason, "rina"]))
request_dump.assert_not_called() request_dump.assert_not_called()
def test_selectTimeout_add_callback(self): def test_selectTimeout_add_callback(self):
"""case add new callback""" """case add new callback"""
self.tunnel._timeouts = [(1, self.tunnel.close)] self.tunnel._timeouts = [(1, self.tunnel.close)]
...@@ -87,7 +81,6 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -87,7 +81,6 @@ class testBaseTunnelManager(unittest.TestCase):
self.assertIn((10, callback), self.tunnel._timeouts) self.assertIn((10, callback), self.tunnel._timeouts)
def test_selectTimeout_removing(self): def test_selectTimeout_removing(self):
"""case remove a callback""" """case remove a callback"""
removed = self.tunnel.babel_dump removed = self.tunnel.babel_dump
...@@ -97,17 +90,14 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -97,17 +90,14 @@ class testBaseTunnelManager(unittest.TestCase):
self.assertEqual(self.tunnel._timeouts, [(1, self.tunnel.close)]) self.assertEqual(self.tunnel._timeouts, [(1, self.tunnel.close)])
def test_selectTimeout_update(self): def test_selectTimeout_update(self):
"""case update a callback""" """case update a callback"""
updated = self.tunnel.babel_dump updated = self.tunnel.babel_dump
self.tunnel._timeouts = [(1, self.tunnel.close), (10, updated)] self.tunnel._timeouts = [(1, self.tunnel.close), (10, updated)]
self.tunnel.selectTimeout(100, updated) self.tunnel.selectTimeout(100, updated)
self.assertEqual(self.tunnel._timeouts, [(1, self.tunnel.close), (100, updated)])
self.assertEqual(self.tunnel._timeouts, [(1, self.tunnel.close), (100, updated)])
@patch("re6st.tunnel.BaseTunnelManager.selectTimeout") @patch("re6st.tunnel.BaseTunnelManager.selectTimeout")
def test_invalidatePeers(self, selectTimeout): def test_invalidatePeers(self, selectTimeout):
...@@ -125,19 +115,18 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -125,19 +115,18 @@ class testBaseTunnelManager(unittest.TestCase):
self.tunnel._peers = [p1, p2, p3] self.tunnel._peers = [p1, p2, p3]
self.tunnel.invalidatePeers() self.tunnel.invalidatePeers()
self.assertEqual(self.tunnel._peers, [p1, p3]) self.assertEqual(self.tunnel._peers, [p1, p3])
selectTimeout.assert_called_once_with(p1.stop_date, self.tunnel.invalidatePeers) selectTimeout.assert_called_once_with(p1.stop_date, self.tunnel.invalidatePeers)
# Because _makeTunnel is defined in sub class of BaseTunnelManager, so i comment
# Because _makeTunnel is defined in sub class of BaseTunnelManager, so i comment
# the follow test # the follow test
# @patch("re6st.tunnel.BaseTunnelManager._makeTunnel", create=True) # @patch("re6st.tunnel.BaseTunnelManager._makeTunnel", create=True)
# def test_processPacket_address_with_msg_peer(self, makeTunnel): # def test_processPacket_address_with_msg_peer(self, makeTunnel):
# """code is 1, peer and msg not none """ # """code is 1, peer and msg not none """
# c = chr(1) # c = chr(1)
# msg = "address" # msg = "address"
# peer = x509.Peer("000001") # peer = x509.Peer("000001")
# self.tunnel._connecting = {peer} # self.tunnel._connecting = {peer}
# self.tunnel._processPacket(c + msg, peer) # self.tunnel._processPacket(c + msg, peer)
...@@ -146,7 +135,6 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -146,7 +135,6 @@ class testBaseTunnelManager(unittest.TestCase):
# self.assertFalse(self.tunnel._connecting) # self.assertFalse(self.tunnel._connecting)
# makeTunnel.assert_called_once_with(peer, msg) # makeTunnel.assert_called_once_with(peer, msg)
def test_processPacket_address(self): def test_processPacket_address(self):
"""code is 1, for address. And peer or msg are none""" """code is 1, for address. And peer or msg are none"""
c = chr(1) c = chr(1)
...@@ -156,13 +144,12 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -156,13 +144,12 @@ class testBaseTunnelManager(unittest.TestCase):
self.assertEqual(res, "1,1;2,2") self.assertEqual(res, "1,1;2,2")
def test_processPacket_address_with_peer(self): def test_processPacket_address_with_peer(self):
"""code is 1, peer is not none, msg is none """code is 1, peer is not none, msg is none
in my opion, this function return address in form address,port,portocl in my opion, this function return address in form address,port,portocl
and each address join by ; and each address join by ;
it will truncate address which has more than 3 element it will truncate address which has more than 3 element
""" """
c = chr(1) c = chr(1)
peer = x509.Peer("000001") peer = x509.Peer("000001")
peer.protocol = 1 peer.protocol = 1
...@@ -172,7 +159,6 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -172,7 +159,6 @@ class testBaseTunnelManager(unittest.TestCase):
res = self.tunnel._processPacket(c, peer) res = self.tunnel._processPacket(c, peer)
self.assertEqual(res, "1,1,1;0,0,0;2,2,2") self.assertEqual(res, "1,1,1;0,0,0;2,2,2")
@patch("re6st.tunnel.BaseTunnelManager.selectTimeout") @patch("re6st.tunnel.BaseTunnelManager.selectTimeout")
def test_processPacket_version(self, selectTimeout): def test_processPacket_version(self, selectTimeout):
...@@ -183,7 +169,6 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -183,7 +169,6 @@ class testBaseTunnelManager(unittest.TestCase):
self.assertEqual(selectTimeout.call_args[0][1], self.tunnel.newVersion) self.assertEqual(selectTimeout.call_args[0][1], self.tunnel.newVersion)
@patch("re6st.x509.Cert.verifyVersion", Mock(return_value=True)) @patch("re6st.x509.Cert.verifyVersion", Mock(return_value=True))
@patch("re6st.tunnel.BaseTunnelManager.selectTimeout") @patch("re6st.tunnel.BaseTunnelManager.selectTimeout")
def test_processPacket_version(self, selectTimeout): def test_processPacket_version(self, selectTimeout):
...@@ -199,16 +184,11 @@ class testBaseTunnelManager(unittest.TestCase): ...@@ -199,16 +184,11 @@ class testBaseTunnelManager(unittest.TestCase):
res = self.tunnel._processPacket(c + version1, peer) res = self.tunnel._processPacket(c + version1, peer)
self.tunnel._processPacket(c + version2, peer) self.tunnel._processPacket(c + version2, peer)
self.assertEqual(res, "00005") self.assertEqual(res, "00005")
self.assertEqual(self.tunnel._version, version2) self.assertEqual(self.tunnel._version, version2)
self.assertEqual(peer.version, version2) self.assertEqual(peer.version, version2)
self.assertEqual(selectTimeout.call_args[0][1], self.tunnel.newVersion) self.assertEqual(selectTimeout.call_args[0][1], self.tunnel.newVersion)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment