commit 177ea49d2e9d168f98f38832719efdda4d38d995 Author: aagbsn aagbsn@extc.org Date: Mon Mar 12 03:58:31 2012 -0700
4297 - Update tests for IP categories
Rings are set up a bit differently now, and broke this test. --- lib/bridgedb/Tests.py | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/lib/bridgedb/Tests.py b/lib/bridgedb/Tests.py index d989f7d..067eafa 100644 --- a/lib/bridgedb/Tests.py +++ b/lib/bridgedb/Tests.py @@ -151,20 +151,25 @@ class IPBridgeDistTests(unittest.TestCase): def testDistWithCategories(self): d = bridgedb.Dist.IPBasedDistributor(self.dumbAreaMapper, 3, "Foo", [RhymesWith255Category()]) - assert len(d.categoryRings) == 1 - rhymesWith255Ring = d.categoryRings[0] + assert len(d.categories) == 1 for _ in xrange(256): d.insert(fakeBridge()) - # Make sure this IP doesn't get any rhymes-with-255 bridges - n = d.getBridgesForIP("1.2.3.4", "x", 10) - for b in n: - self.assertFalse(b.getID() in rhymesWith255Ring.bridgesByID) - - # Make sure these IPs all get rhymes-with-255 bridges - for ip in ("6.7.8.255", "10.10.10.255"): - n = d.getBridgesForIP("1.2.3.255", "xyz", 10) + + for _ in xrange(256): + # Make sure that the categories do not overlap + f = lambda: ".".join([str(random.randrange(1,255)) for _ in xrange(4)]) + g = lambda: ".".join([str(random.randrange(1,255)) for _ in xrange(3)] + ['255']) + n = d.getBridgesForIP(g(), "x", 10) + n2 = d.getBridgesForIP(f(), "x", 10) + + assert(len(n) > 0) + assert(len(n2) > 0) + for b in n: - self.assertTrue(b.getID() in rhymesWith255Ring.bridgesByID) + assert (b not in n2) + + for b in n2: + assert (b not in n)
def testDistWithPortRestrictions(self): param = bridgedb.Bridges.BridgeRingParameters(needPorts=[(443, 1)])