From fe6ff466d865b6e291bc7920d38a12c386f4a62d Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 30 Dec 2016 23:40:47 -0500 Subject: [PATCH] more coverage: parse_tcp_v1_hint --- src/wormhole/test/test_transit.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/wormhole/test/test_transit.py b/src/wormhole/test/test_transit.py index 657f9e6..e04d9f1 100644 --- a/src/wormhole/test/test_transit.py +++ b/src/wormhole/test/test_transit.py @@ -167,6 +167,23 @@ class Hints(unittest.TestCase): self.assertEqual(r2, r3) self.assertEqual(len(set([r1, r2, r3])), 1) + def test_parse_tcp_v1_hint(self): + c = transit.Common("") + p = c._parse_tcp_v1_hint + self.assertEqual(p({"type": "unknown"}), None) + h = p({"type": "direct-tcp-v1", "hostname": "foo", "port": 1234}) + self.assertEqual(h, transit.DirectTCPV1Hint("foo", 1234)) + h = p({"type": "tor-tcp-v1", "hostname": "foo", "port": 1234}) + self.assertEqual(h, transit.TorTCPV1Hint("foo", 1234)) + self.assertEqual(p({"type": "direct-tcp-v1"}), + None) # missing hostname + self.assertEqual(p({"type": "direct-tcp-v1", "hostname": 12}), + None) # invalid hostname + self.assertEqual(p({"type": "direct-tcp-v1", "hostname": "foo"}), + None) # missing port + self.assertEqual(p({"type": "direct-tcp-v1", "hostname": "foo", + "port": "not a number"}), + None) # invalid port class Basic(unittest.TestCase): @inlineCallbacks