~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

Connection sharing, with redirection. without authentification.

* bzrlib/transport/http/_urllib.py:
(Request): Deleted. The _urllib2 version is shiniest.
(HttpTransport_urllib): Share connections.
(HttpTransport_urllib._perform): New method.
(HttpTransport_urllib._get): Takes the _urllib2_wrappers into
account.
(HttpTransport_urllib._get_url_impl): Deleted.
(HttpTransport_urllib._head): New method.
(HttpTransport_urllib.has): Takes the _urllib2_wrappers into
account.
(HttpTransport_urllib.copy_to, HttpTransport_urllib.move,
HttpTransport_urllib.delete): Deleted. Were carbon copies of
HttpTransportBase.

* bzrlib/tests/test_http.py:
(TestHttpConnections_urllib.test_has_on_bogus_host): The timeout
was too high, at least on Mac OS X 10.3 the test was taking a
whole *minute*. Also, the new implementation raise a nice
ConnectionError.

* bzrlib/errors.py:
(ConnectionError): Don't don't repeat ConnectionError.

* bzrlib/transport/http/_urllib2_wrappers.py: 
New file. Wrappers around urllib2 framework.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import socket
23
23
 
24
24
import bzrlib
25
 
from bzrlib.errors import DependencyNotPresent
 
25
from bzrlib.errors import (DependencyNotPresent,
 
26
                           ConnectionError,
 
27
                           )
26
28
from bzrlib.tests import TestCase, TestSkipped
27
29
from bzrlib.transport import Transport
28
30
from bzrlib.transport.http import extract_auth, HttpTransportBase
138
140
        self._prep_tree()
139
141
 
140
142
    def test_has_on_bogus_host(self):
141
 
        import urllib2
142
 
        # Get a random address, so that we can be sure there is no
143
 
        # http handler there.
144
 
        s = socket.socket()
145
 
        s.bind(('localhost', 0))
146
 
        t = self._transport('http://%s:%s/' % s.getsockname())
147
 
        self.assertRaises(urllib2.URLError, t.has, 'foo/bar')
 
143
        # Get a free address and don't 'accept' on it, so that we
 
144
        # can be sure there is no http handler there, but set a
 
145
        # reasonable timeout to not slow down tests too much.
 
146
        default_timeout = socket.getdefaulttimeout()
 
147
        try:
 
148
            socket.setdefaulttimeout(2)
 
149
            s = socket.socket()
 
150
            s.bind(('localhost', 0))
 
151
            t = self._transport('http://%s:%s/' % s.getsockname())
 
152
            self.assertRaises(ConnectionError, t.has, 'foo/bar')
 
153
        finally:
 
154
            socket.setdefaulttimeout(default_timeout)
 
155
 
148
156
 
149
157
 
150
158
class TestHttpConnections_pycurl(TestCaseWithWebserver, TestHttpMixins):