[tor-commits] [bridgedb/develop] Add tests for https.request.HTTPSBridgeRequest and BridgeRequestBase.

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


commit 8cd195e2a518694094f53bb24921eb499e31c270
Author: Isis Lovecruft <isis at torproject.org>
Date:   Tue Apr 14 10:15:23 2015 +0000

    Add tests for https.request.HTTPSBridgeRequest and BridgeRequestBase.
---
 lib/bridgedb/test/test_bridgerequest.py |   18 +++++++-
 lib/bridgedb/test/test_https_request.py |   75 +++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/lib/bridgedb/test/test_bridgerequest.py b/lib/bridgedb/test/test_bridgerequest.py
index b4da71b..3392a4e 100644
--- a/lib/bridgedb/test/test_bridgerequest.py
+++ b/lib/bridgedb/test/test_bridgerequest.py
@@ -40,5 +40,19 @@ class BridgeRequestBaseTests(unittest.TestCase):
         """BridgeRequestBase.withPluggableTransportType() should add the
         pluggable transport type to the ``transport`` attribute.
         """
-        self.request.withPluggableTransportType('huggable-transport')
-        self.assertIn('huggable-transport', self.request.transports)
+        self.request.withPluggableTransportType('huggable_transport')
+        self.assertIn('huggable_transport', self.request.transports)
+
+    def test_BridgeRequestBase_getHashringPlacement_without_client(self):
+        """BridgeRequestBase.getHashringPlacement() without a client parameter
+        should use the default client identifier string.
+        """
+        self.assertEqual(self.request.getHashringPlacement('AAAA'),
+                         3486762050L)
+
+    def test_BridgeRequestBase_getHashringPlacement_with_client(self):
+        """BridgeRequestBase.getHashringPlacement() with a client parameter
+        should use the client identifier string.
+        """
+        self.assertEqual(self.request.getHashringPlacement('AAAA', client='you'),
+                         2870307088L)
diff --git a/lib/bridgedb/test/test_https_request.py b/lib/bridgedb/test/test_https_request.py
new file mode 100644
index 0000000..f4f6640
--- /dev/null
+++ b/lib/bridgedb/test/test_https_request.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+#_____________________________________________________________________________
+#
+# This file is part of BridgeDB, a Tor bridge distribution system.
+#
+# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 <isis at torproject.org>
+#           please also see AUTHORS file
+# :copyright: (c) 2007-2015, The Tor Project, Inc.
+#             (c) 2014-2015, Isis Lovecruft
+# :license: see LICENSE for licensing information
+#_____________________________________________________________________________
+
+
+from twisted.trial import unittest
+
+from bridgedb.bridgerequest import IRequestBridges
+from bridgedb.https import request 
+
+
+class MockRequest(object):
+    def __init__(self, args):
+        self.args = args
+
+
+class HTTPSBridgeRequestTests(unittest.TestCase):
+    """Unittests for :class:`bridgedb.https.request.HTTPSBridgeRequest`."""
+
+    def setUp(self):
+        """Setup test run."""
+        self.request = request.HTTPSBridgeRequest()
+
+    def test_HTTPSBridgeRequest_implements_IRequestBridges(self):
+        """HTTPSBridgeRequest should implement IRequestBridges interface."""
+        self.assertTrue(IRequestBridges.implementedBy(request.HTTPSBridgeRequest))
+
+    def test_HTTPSBridgeRequest_withIPversion(self):
+        """HTTPSBridgeRequest.withIPversion({ipv6=[…]}) should store that the
+        client wanted IPv6 bridges."""
+        parameters = {'ipv6': 'wooooooooo'}
+        self.request.withIPversion(parameters)
+
+    def test_HTTPSBridgeRequest_withoutBlockInCountry_IR(self):
+        """HTTPSBridgeRequest.withoutBlockInCountry() should add the country CC
+        to the ``notBlockedIn`` attribute.
+        """
+        httprequest = MockRequest({'unblocked': ['IR']})
+        self.request.withoutBlockInCountry(httprequest)
+        self.assertIn('IR', self.request.notBlockedIn)
+
+    def test_HTTPSBridgeRequest_withoutBlockInCountry_US(self):
+        """HTTPSBridgeRequest.withoutBlockInCountry() should add the country CC
+        to the ``notBlockedIn`` attribute (and not any other countries).
+        """
+        httprequest = MockRequest({'unblocked': ['US']})
+        self.request.withoutBlockInCountry(httprequest)
+        self.assertNotIn('IR', self.request.notBlockedIn)
+
+    def test_HTTPSBridgeRequest_withoutBlockInCountry_no_addClientCountryCode(self):
+        """HTTPSBridgeRequest.withoutBlockInCountry(), when
+        addClientCountryCode=False, shouldn't add the client's country code to the
+        ``notBlockedIn`` attribute.
+        """
+        httprequest = MockRequest({'unblocked': ['NL']})
+        self.request = request.HTTPSBridgeRequest(addClientCountryCode=False)
+        self.request.client = '5.5.5.5'
+        self.request.withoutBlockInCountry(httprequest)
+        self.assertItemsEqual(['NL'], self.request.notBlockedIn)
+
+    def test_HTTPSBridgeRequest_withPluggableTransportType(self):
+        """HTTPSBridgeRequest.withPluggableTransportType() should add the
+        pluggable transport type to the ``transport`` attribute.
+        """
+        httprequest = MockRequest({'transport': ['huggable_transport']})
+        self.request.withPluggableTransportType(httprequest.args)
+        self.assertIn('huggable_transport', self.request.transports)





More information about the tor-commits mailing list