~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/HTTPTestUtil.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:
170
170
    def setUp(self):
171
171
        super(TestCaseWithWebserver, self).setUp()
172
172
        self.transport_readonly_server = HttpServer
 
173
 
 
174
 
 
175
class TestCaseWithTwoWebservers(TestCaseWithWebserver):
 
176
    """A support class providinf readonly urls (on two servers) that are http://.
 
177
 
 
178
    We setup two webservers to allows various tests involving
 
179
    proxies or redirections from one server to the other.
 
180
    """
 
181
    def setUp(self):
 
182
        super(TestCaseWithTwoWebservers, self).setUp()
 
183
        self.transport_secondary_server = HttpServer
 
184
        self.__secondary_server = None
 
185
 
 
186
    def create_transport_secondary_server(self):
 
187
        """Create a transport server from class defined at init.
 
188
 
 
189
        This is mostly a hook for daughter classes.
 
190
        """
 
191
        return self.transport_secondary_server()
 
192
 
 
193
    def get_secondary_server(self):
 
194
        """Get the server instance for the secondary transport."""
 
195
        if self.__secondary_server is None:
 
196
            self.__secondary_server = self.create_transport_secondary_server()
 
197
            self.__secondary_server.setUp()
 
198
            # Note that addCleanup ensures that last added
 
199
            # callables are called first. That will ensures that
 
200
            # our cleanup is called before the other http server
 
201
            # cleanup if we are created last and our cleanup is
 
202
            # called after the other http server cleanup if we
 
203
            # are created first.
 
204
            self.addCleanup(self.__secondary_server.tearDown)
 
205
        return self.__secondary_server
 
206
 
 
207
 
 
208
class FakeProxyRequestHandler(TestingHTTPRequestHandler):
 
209
    """Append a '-proxied' suffix to file served"""
 
210
 
 
211
    def translate_path(self, path):
 
212
        return TestingHTTPRequestHandler.translate_path(self,
 
213
                                                        path + '-proxied')
 
214
 
 
215