/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/HTTPTestUtil.py

Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
            self.send_response(0, "Bad status")
50
50
            self.end_headers()
51
51
        except socket.error, e:
52
 
            if (len(e.args) > 0) and (e.args[0] == errno.EPIPE):
53
 
                # We don't want to pollute the test reuslts with
54
 
                # spurious server errors while test succeed. In
55
 
                # our case, it may occur that the test have
56
 
                # already read the 'Bad Status' and closed the
57
 
                # socket while we are still trying to send some
58
 
                # headers... So the test is ok but if we raise
59
 
                # the exception the output is dirty. So we don't
60
 
                # raise, but we close the connection, just to be
61
 
                # safe :)
 
52
            # We don't want to pollute the test results with
 
53
            # spurious server errors while test succeed. In our
 
54
            # case, it may occur that the test has already read
 
55
            # the 'Bad Status' and closed the socket while we are
 
56
            # still trying to send some headers... So the test is
 
57
            # ok, but if we raise the exception, the output is
 
58
            # dirty. So we don't raise, but we close the
 
59
            # connection, just to be safe :)
 
60
            spurious = [errno.EPIPE,
 
61
                        errno.ECONNRESET,
 
62
                        errno.ECONNABORTED,
 
63
                        ]
 
64
            if (len(e.args) > 0) and (e.args[0] in spurious):
62
65
                self.close_connection = 1
63
66
                pass
64
67
            else:
171
174
    def setUp(self):
172
175
        super(TestCaseWithWebserver, self).setUp()
173
176
        self.transport_readonly_server = HttpServer
 
177
 
 
178
 
 
179
class TestCaseWithTwoWebservers(TestCaseWithWebserver):
 
180
    """A support class providinf readonly urls (on two servers) that are http://.
 
181
 
 
182
    We setup two webservers to allows various tests involving
 
183
    proxies or redirections from one server to the other.
 
184
    """
 
185
    def setUp(self):
 
186
        super(TestCaseWithTwoWebservers, self).setUp()
 
187
        self.transport_secondary_server = HttpServer
 
188
        self.__secondary_server = None
 
189
 
 
190
    def create_transport_secondary_server(self):
 
191
        """Create a transport server from class defined at init.
 
192
 
 
193
        This is mostly a hook for daughter classes.
 
194
        """
 
195
        return self.transport_secondary_server()
 
196
 
 
197
    def get_secondary_server(self):
 
198
        """Get the server instance for the secondary transport."""
 
199
        if self.__secondary_server is None:
 
200
            self.__secondary_server = self.create_transport_secondary_server()
 
201
            self.__secondary_server.setUp()
 
202
            self.addCleanup(self.__secondary_server.tearDown)
 
203
        return self.__secondary_server
 
204
 
 
205
 
 
206
class FakeProxyRequestHandler(TestingHTTPRequestHandler):
 
207
    """Append a '-proxied' suffix to file served"""
 
208
 
 
209
    def translate_path(self, path):
 
210
        return TestingHTTPRequestHandler.translate_path(self,
 
211
                                                        path + '-proxied')
 
212
 
 
213