~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/HTTPTestUtil.py

  • Committer: John Arbash Meinel
  • Date: 2006-12-18 19:21:11 UTC
  • mfrom: (2196 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2209.
  • Revision ID: john@arbash-meinel.com-20061218192111-3fc13nmt21u3f1wm
[merge] bzr.dev 2196

Show diffs side-by-side

added added

removed removed

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