~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-13 23:16:20 UTC
  • mfrom: (4957 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4960.
  • Revision ID: andrew.bennetts@canonical.com-20100113231620-n6in2yjib2v6z03g
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
218
218
    def get_url(self):
219
219
        return '%s://%s:%s/' % (self.scheme, self.host, self.port)
220
220
 
221
 
    def setUp(self):
 
221
    def start_server(self):
222
222
        self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
223
223
        self._sock.bind(('127.0.0.1', 0))
224
224
        self.host, self.port = self._sock.getsockname()
247
247
            # The client may have already closed the socket.
248
248
            pass
249
249
 
250
 
    def tearDown(self):
 
250
    def stop_server(self):
251
251
        try:
252
252
            self._sock.close()
253
253
        except socket.error:
306
306
 
307
307
        server = http_server.HttpServer(BogusRequestHandler)
308
308
        try:
309
 
            self.assertRaises(httplib.UnknownProtocol, server.setUp)
 
309
            self.assertRaises(httplib.UnknownProtocol, server.start_server)
310
310
        except:
311
 
            server.tearDown()
 
311
            server.stop_server()
312
312
            self.fail('HTTP Server creation did not raise UnknownProtocol')
313
313
 
314
314
    def test_force_invalid_protocol(self):
315
315
        server = http_server.HttpServer(protocol_version='HTTP/0.1')
316
316
        try:
317
 
            self.assertRaises(httplib.UnknownProtocol, server.setUp)
 
317
            self.assertRaises(httplib.UnknownProtocol, server.start_server)
318
318
        except:
319
 
            server.tearDown()
 
319
            server.stop_server()
320
320
            self.fail('HTTP Server creation did not raise UnknownProtocol')
321
321
 
322
322
    def test_server_start_and_stop(self):
323
323
        server = http_server.HttpServer()
324
 
        server.setUp()
 
324
        server.start_server()
325
325
        try:
326
326
            self.assertTrue(server._http_running)
327
327
        finally:
328
 
            server.tearDown()
 
328
            server.stop_server()
329
329
        self.assertFalse(server._http_running)
330
330
 
331
331
    def test_create_http_server_one_zero(self):
428
428
    def test_http_impl_urls(self):
429
429
        """There are servers which ask for particular clients to connect"""
430
430
        server = self._server()
431
 
        server.setUp()
 
431
        server.start_server()
432
432
        try:
433
433
            url = server.get_url()
434
434
            self.assertTrue(url.startswith('%s://' % self._qualified_prefix))
435
435
        finally:
436
 
            server.tearDown()
 
436
            server.stop_server()
437
437
 
438
438
 
439
439
class TestHttps_pycurl(TestWithTransport_pycurl, tests.TestCase):
763
763
        self.assertEqual(None, server.host)
764
764
        self.assertEqual(None, server.port)
765
765
 
766
 
    def test_setUp_and_tearDown(self):
 
766
    def test_setUp_and_stop(self):
767
767
        server = RecordingServer(expect_body_tail=None)
768
 
        server.setUp()
 
768
        server.start_server()
769
769
        try:
770
770
            self.assertNotEqual(None, server.host)
771
771
            self.assertNotEqual(None, server.port)
772
772
        finally:
773
 
            server.tearDown()
 
773
            server.stop_server()
774
774
        self.assertEqual(None, server.host)
775
775
        self.assertEqual(None, server.port)
776
776
 
1964
1964
    def setUp(self):
1965
1965
        tests.TestCase.setUp(self)
1966
1966
        self.server = self._activity_server(self._protocol_version)
1967
 
        self.server.setUp()
 
1967
        self.server.start_server()
1968
1968
        self.activities = {}
1969
1969
        def report_activity(t, bytes, direction):
1970
1970
            count = self.activities.get(direction, 0)
1979
1979
 
1980
1980
    def tearDown(self):
1981
1981
        self._transport._report_activity = self.orig_report_activity
1982
 
        self.server.tearDown()
 
1982
        self.server.stop_server()
1983
1983
        tests.TestCase.tearDown(self)
1984
1984
 
1985
1985
    def get_transport(self):
2105
2105
    def setUp(self):
2106
2106
        tests.TestCase.setUp(self)
2107
2107
        self.server = self._activity_server(self._protocol_version)
2108
 
        self.server.setUp()
 
2108
        self.server.start_server()
2109
2109
        self.activities = {}
2110
2110
        def report_activity(t, bytes, direction):
2111
2111
            count = self.activities.get(direction, 0)
2120
2120
 
2121
2121
    def tearDown(self):
2122
2122
        self._transport._report_activity = self.orig_report_activity
2123
 
        self.server.tearDown()
 
2123
        self.server.stop_server()
2124
2124
        tests.TestCase.tearDown(self)
2125
2125
 
2126
2126
 
2136
2136
        self.server = ActivityHTTPServer('HTTP/1.1')
2137
2137
        self._transport=_urllib.HttpTransport_urllib
2138
2138
 
2139
 
        self.server.setUp()
 
2139
        self.server.start_server()
2140
2140
 
2141
2141
        # We override at class level because constructors may propagate the
2142
2142
        # bound method and render instance overriding ineffective (an
2146
2146
 
2147
2147
    def tearDown(self):
2148
2148
        self._transport._report_activity = self.orig_report_activity
2149
 
        self.server.tearDown()
 
2149
        self.server.stop_server()
2150
2150
        tests.TestCase.tearDown(self)
2151
2151
 
2152
2152
    def assertActivitiesMatch(self):