[tor-commits] [bridgedb/develop] Separate DummyBridge._randomORPort() into its own test utility.

isis at torproject.org isis at torproject.org
Thu Jun 25 07:10:54 UTC 2015


commit 0214b0e9ddceca512bd8b7a9c3b052572c4511e4
Author: Isis Lovecruft <isis at torproject.org>
Date:   Sat Apr 18 00:50:36 2015 +0000

    Separate DummyBridge._randomORPort() into its own test utility.
---
 lib/bridgedb/test/util.py |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/bridgedb/test/util.py b/lib/bridgedb/test/util.py
index fe662da..4aa2709 100644
--- a/lib/bridgedb/test/util.py
+++ b/lib/bridgedb/test/util.py
@@ -118,6 +118,9 @@ def bracketIPv6(ip):
     """Put brackets around an IPv6 address, just as tor does."""
     return "[%s]" % ip
 
+def randomPort():
+    return random.randint(1, 65535)
+
 def randomIPv4():
     return ipaddr.IPv4Address(random.getrandbits(32))
 
@@ -185,8 +188,6 @@ class DummyBridge(object):
 
     ptArgs = {}
 
-    def _randORPort(self): return random.randint(9001, 9999)
-
     def __init__(self):
         """Create a mocked bridge suitable for testing distributors and web
         resource rendering.
@@ -194,12 +195,10 @@ class DummyBridge(object):
         ipv4 = randomIPv4()
         self.nickname = "bridge-{0}".format(ipv4)
         self.address = ipaddr.IPv4Address(ipv4)
-        self.orPort = self._randORPort()
+        self.orPort = randomPort()
         self.fingerprint = "".join(random.choice('abcdef0123456789')
                                    for _ in xrange(40))
-        self.orAddresses = [
-            (randomIPv6(), self._randORPort(), 6)
-        ]
+        self.orAddresses = [(randomIPv6(), randomPort(), 6)]
 
     def getBridgeLine(self, bridgeRequest, includeFingerprint=True):
         """Get a "torrc" bridge config line to give to a client."""





More information about the tor-commits mailing list