commit 6fcf0121296067f7e47721af315ca5b85021e8b8 Author: Isis Lovecruft <i...@torproject.org> Date: Wed Mar 19 17:56:26 2014 +0000
Add a mocked DummyIPBasedDistributor class to test_HTTPServer.py. A distributor is a required parameter to the `HTTPServer.WebResourceBridges` class. This one merely creates N random `DummyBridges`, where N is the number of bridges we're told to return to the client. --- lib/bridgedb/test/test_HTTPServer.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/bridgedb/test/test_HTTPServer.py b/lib/bridgedb/test/test_HTTPServer.py index 05e041c..e2856c7 100644 --- a/lib/bridgedb/test/test_HTTPServer.py +++ b/lib/bridgedb/test/test_HTTPServer.py @@ -418,3 +418,30 @@ class DummyBridge(object): bridgeLine = " ".join([item for item in line]) #print "Created config line: %r" % bridgeLine return bridgeLine + + +class DummyIPBasedDistributor(object): + """A mocked :class:`bridgedb.Dist.IPBasedDistributor` which is used to test + :class:`bridgedb.HTTPServer.WebResourceBridges. + """ + + def _dumbAreaMapper(ip): return ip + + def __init__(self, areaMapper=None, nClusters=None, key=None, + ipCategories=None, answerParameters=None): + """None of the parameters are really used, they are just there to retain + an identical method signature. + """ + self.areaMapper = self._dumbAreaMapper + self.nClusters = 3 + self.nBridgesToGive = 3 + self.key = self.__class__.__name__ + self.ipCategories = ipCategories + self.answerParameters = answerParameters + + def getBridgesForIP(self, ip=None, epoch=None, N=1, + countyCode=None, bridgeFilterRules=None): + """Needed because it's called in + :meth:`WebResourceBridges.getBridgesForIP`. + """ + return [DummyBridge() for _ in xrange(N)] _______________________________________________ tor-commits mailing list tor-commits@lists.torproject.org https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits