~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

Merge pt1 hooks branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import bzrlib
33
33
from bzrlib import (
34
34
    bzrdir,
 
35
    cethread,
35
36
    config,
36
37
    errors,
37
38
    osutils,
178
179
        self._sock.bind(('127.0.0.1', 0))
179
180
        self.host, self.port = self._sock.getsockname()
180
181
        self._ready = threading.Event()
181
 
        self._thread = test_server.ThreadWithException(
182
 
            event=self._ready, target=self._accept_read_and_reply)
 
182
        self._thread = test_server.TestThread(
 
183
            sync_event=self._ready, target=self._accept_read_and_reply)
183
184
        self._thread.start()
184
185
        if 'threads' in tests.selftest_debug_flags:
185
186
            sys.stderr.write('Thread started: %s\n' % (self._thread.ident,))
1079
1080
        handler.set_proxy(request, 'http')
1080
1081
        return request
1081
1082
 
 
1083
    def assertEvaluateProxyBypass(self, expected, host, no_proxy):
 
1084
        handler = _urllib2_wrappers.ProxyHandler()
 
1085
        self.assertEquals(expected,
 
1086
                          handler.evaluate_proxy_bypass(host, no_proxy))
 
1087
 
1082
1088
    def test_empty_user(self):
1083
1089
        self.overrideEnv('http_proxy', 'http://bar.com')
1084
1090
        request = self._proxied_request()
1089
1095
        self.overrideEnv('http_proxy', 'host:1234')
1090
1096
        self.assertRaises(errors.InvalidURL, self._proxied_request)
1091
1097
 
 
1098
    def test_evaluate_proxy_bypass_true(self):
 
1099
        """The host is not proxied"""
 
1100
        self.assertEvaluateProxyBypass(True, 'example.com', 'example.com')
 
1101
        self.assertEvaluateProxyBypass(True, 'bzr.example.com', '*example.com')
 
1102
 
 
1103
    def test_evaluate_proxy_bypass_false(self):
 
1104
        """The host is proxied"""
 
1105
        self.assertEvaluateProxyBypass(False, 'bzr.example.com', None)
 
1106
 
 
1107
    def test_evaluate_proxy_bypass_unknown(self):
 
1108
        """The host is not explicitly proxied"""
 
1109
        self.assertEvaluateProxyBypass(None, 'example.com', 'not.example.com')
 
1110
        self.assertEvaluateProxyBypass(None, 'bzr.example.com', 'example.com')
 
1111
 
 
1112
    def test_evaluate_proxy_bypass_empty_entries(self):
 
1113
        """Ignore empty entries"""
 
1114
        self.assertEvaluateProxyBypass(None, 'example.com', '')
 
1115
        self.assertEvaluateProxyBypass(None, 'example.com', ',')
 
1116
        self.assertEvaluateProxyBypass(None, 'example.com', 'foo,,bar')
 
1117
 
1092
1118
 
1093
1119
class TestProxyHttpServer(http_utils.TestCaseWithTwoWebservers):
1094
1120
    """Tests proxy server.