~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/HttpServer.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-12-11 13:24:55 UTC
  • mto: (2182.1.1 Aaron's integration)
  • mto: This revision was merged to the branch mainline in revision 2183.
  • Revision ID: v.ladeuil+lp@free.fr-20061211132455-e8k81db8ktfwvrlz
Tests for proxies, covering  #74759.

* bzrlib/transport/http/_urllib2_wrappers.py:
(ProxyHandler.proxy_bypass): Matches against the modified regexp,
not the original domain.

* bzrlib/tests/test_http.py:
(TestProxyHttpServer, TestProxyHttpServer_urllib,
TestProxyHttpServer_pycurl): New classes for proxy tests.

* bzrlib/tests/HttpServer.py:
(HttpServer._http_start): Give access to the port used by the
server socket.
(HttpServer.setUp, HttpServer.tearDown): Handles the 'no_proxy'
env var too.

* bzrlib/tests/HTTPTestUtil.py:
(TestCaseWithTwoWebservers): New class for tests needing two
related web servers.
(FakeProxyRequestHandler): New class to fake a proxy http server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
248
248
    def _http_start(self):
249
249
        httpd = None
250
250
        httpd = self._get_httpd()
251
 
        host, port = httpd.socket.getsockname()
252
 
        self._http_base_url = '%s://localhost:%s/' % (self._url_protocol, port)
 
251
        host, self.port = httpd.socket.getsockname()
 
252
        self._http_base_url = '%s://localhost:%s/' % (self._url_protocol,
 
253
                                                      self.port)
253
254
        self._http_starting.release()
254
255
        httpd.socket.settimeout(0.1)
255
256
 
287
288
        self._http_base_url = None
288
289
        self._http_thread = threading.Thread(target=self._http_start)
289
290
        self._http_thread.setDaemon(True)
290
 
        self._http_thread.start()
 
291
        # Ensure we are not influenced by the environment
291
292
        self._http_proxy = os.environ.get("http_proxy")
292
293
        if self._http_proxy is not None:
293
294
            del os.environ["http_proxy"]
 
295
        self._no_proxy = os.environ.get("no_proxy")
 
296
        if self._no_proxy is not None:
 
297
            del os.environ["no_proxy"]
 
298
        self._http_thread.start()
294
299
        self.logs = []
295
300
 
296
301
    def tearDown(self):
297
302
        """See bzrlib.transport.Server.tearDown."""
298
303
        self._http_running = False
299
304
        self._http_thread.join()
300
 
        if self._http_proxy is not None:
301
 
            import os
 
305
        if self._http_proxy is None:
 
306
            if os.environ.get("http_proxy") is not None:
 
307
                del os.environ["http_proxy"]
 
308
        else:
302
309
            os.environ["http_proxy"] = self._http_proxy
 
310
        if self._no_proxy is None:
 
311
            if os.environ.get("no_proxy") is not None:
 
312
                del os.environ["no_proxy"]
 
313
        else:
 
314
            os.environ["no_proxy"] = self.no_proxy
303
315
 
304
316
    def get_url(self):
305
317
        """See bzrlib.transport.Server.get_url."""