~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

Better (but still incomplete) design for bogus servers.

* bzrlib/transport/http/_urllib2_wrappers.py:
(AbstractHTTPHandler): Add 'Accept: */*' again to default headers
until I fully understand why and when it's needed or not (curl add
it if no Accept header is present).

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._curl_perform): CURLE_GOT_NOTHING may be
considered as a ConnectionError, inspection of curl code reveals
that the case is sufficiently rare and low level related to not be
considered an http error per se.

* bzrlib/transport/http/__init__.py:
(WallHttpServer): Deleted.

* bzrlib/tests/test_http.py:
(TestBogusServer): Factor out the tests common to the bogus
servers.

* bzrlib/tests/__init__.py:
(TestCaseWithTransport.create_transport_server,
TestCaseWithTransport.create_transport_readonly_server): New
methods, allows test cases to specify the transport servers
without defining useless classes.
(TestCaseWithTransport.get_readonly_server): Use
create_transport_readonly_server.
(TestCaseWithTransport.get_server): Use create_transport_server.

* bzrlib/tests/HTTPTestUtil.py:
(TestCaseWithWebserver): Fix typo in doc string.
(TestCaseWithWallserver): Deleted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
                           )
28
28
from bzrlib.tests import TestCase, TestSkipped
29
29
from bzrlib.transport import Transport
30
 
from bzrlib.transport.http import extract_auth, HttpTransportBase
 
30
from bzrlib.transport.http import (
 
31
    extract_auth,
 
32
    HttpTransportBase,
 
33
    WallRequestHandler,
 
34
    )
31
35
from bzrlib.transport.http._urllib import HttpTransport_urllib
32
 
from bzrlib.tests.HTTPTestUtil import (
33
 
    TestCaseWithWebserver,
34
 
    TestCaseWithWallserver,
35
 
    )
 
36
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
36
37
 
37
38
 
38
39
class FakeManager (object):
236
237
# way to add an accessor or an attribute to this transports so
237
238
# that we can filter them from the list of all existing
238
239
# transports ?
239
 
class TestWallServer(TestCaseWithWallserver):
240
 
    """Tests that we get the right exceptions during the connection phase"""
 
240
class TestBogusServer(TestCaseWithWebserver):
 
241
    """Abstract class to define test for all bogus servers"""
241
242
 
242
 
    from bzrlib.transport.http._pycurl import PyCurlTransport
243
 
#    _transport = PyCurlTransport
 
243
    #from bzrlib.transport.http._pycurl import PyCurlTransport
 
244
    #_transport = PyCurlTransport
244
245
    _transport = HttpTransport_urllib
245
246
 
246
247
    def test_has(self):
247
 
        server = self.get_readonly_server()
 
248
        server = self.get_server()
248
249
        t = self._transport(server.get_url())
249
250
        self.assertRaises(ConnectionError, t.has, 'foo/bar')
 
251
 
 
252
    def test_get(self):
 
253
        server = self.get_server()
 
254
        t = self._transport(server.get_url())
 
255
        self.assertRaises(ConnectionError, t.get, 'foo/bar')
 
256
 
 
257
 
 
258
class TestWallServer(TestBogusServer):
 
259
    """Tests that we get the right exceptions during the connection phase"""
 
260
    def create_transport_server(self):
 
261
        return bzrlib.transport.http.HttpServer(WallRequestHandler)