~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

Merge bzr.urllib.keepalive

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from bzrlib.transport import Transport
30
30
from bzrlib.transport.http import extract_auth, HttpTransportBase
31
31
from bzrlib.transport.http._urllib import HttpTransport_urllib
32
 
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
 
32
from bzrlib.tests.HTTPTestUtil import (
 
33
    TestCaseWithWebserver,
 
34
    TestCaseWithWallserver,
 
35
    )
33
36
 
34
37
 
35
38
class FakeManager (object):
36
39
 
37
40
    def __init__(self):
38
41
        self.credentials = []
39
 
        
 
42
 
40
43
    def add_password(self, realm, host, username, password):
41
44
        self.credentials.append([realm, host, username, password])
42
45
 
51
54
        url = extract_auth('http://user:pass@www.bazaar-vcs.org/bzr/bzr.dev', f)
52
55
        self.assertEquals('http://www.bazaar-vcs.org/bzr/bzr.dev', url)
53
56
        self.assertEquals(1, len(f.credentials))
54
 
        self.assertEquals([None, 'www.bazaar-vcs.org', 'user', 'pass'], f.credentials[0])
55
 
        
 
57
        self.assertEquals([None, 'www.bazaar-vcs.org', 'user', 'pass'],
 
58
                          f.credentials[0])
 
59
 
56
60
    def test_abs_url(self):
57
61
        """Construction of absolute http URLs"""
58
62
        t = HttpTransport_urllib('http://bazaar-vcs.org/bzr/bzr.dev/')
59
63
        eq = self.assertEqualDiff
60
64
        eq(t.abspath('.'),
61
65
           'http://bazaar-vcs.org/bzr/bzr.dev')
62
 
        eq(t.abspath('foo/bar'), 
 
66
        eq(t.abspath('foo/bar'),
63
67
           'http://bazaar-vcs.org/bzr/bzr.dev/foo/bar')
64
68
        eq(t.abspath('.bzr'),
65
69
           'http://bazaar-vcs.org/bzr/bzr.dev/.bzr')
106
110
        t = self._transport(server.get_url())
107
111
        self.assertEqual(t.has('foo/bar'), True)
108
112
        self.assertEqual(len(server.logs), 1)
109
 
        self.assertContainsRe(server.logs[0], 
 
113
        self.assertContainsRe(server.logs[0],
110
114
            r'"HEAD /foo/bar HTTP/1.." (200|302) - "-" "bzr/')
111
115
 
112
116
    def test_http_has_not_found(self):
113
117
        server = self.get_readonly_server()
114
118
        t = self._transport(server.get_url())
115
119
        self.assertEqual(t.has('not-found'), False)
116
 
        self.assertContainsRe(server.logs[1], 
 
120
        self.assertContainsRe(server.logs[1],
117
121
            r'"HEAD /not-found HTTP/1.." 404 - "-" "bzr/')
118
122
 
119
123
    def test_http_get(self):
151
155
            socket.setdefaulttimeout(default_timeout)
152
156
 
153
157
 
154
 
 
155
158
class TestHttpConnections_pycurl(TestCaseWithWebserver, TestHttpMixins):
156
159
 
157
160
    def _get_pycurl_maybe(self):
168
171
        self._prep_tree()
169
172
 
170
173
 
171
 
 
172
174
class TestHttpTransportRegistration(TestCase):
173
175
    """Test registrations of various http implementations"""
174
176
 
228
230
        self.check_header('0-9,300-5000,-50',
229
231
                          ranges=[(0,9), (300,5000)],
230
232
                          tail=50)
 
233
 
 
234
# TODO: We need to generalize the following tests to all
 
235
# transports which connect to a server via a socket. Is there a
 
236
# way to add an accessor or an attribute to this transports so
 
237
# that we can filter them from the list of all existing
 
238
# transports ?
 
239
class TestWallServer(TestCaseWithWallserver):
 
240
    """Tests that we get the right exceptions during the connection phase"""
 
241
 
 
242
    from bzrlib.transport.http._pycurl import PyCurlTransport
 
243
#    _transport = PyCurlTransport
 
244
    _transport = HttpTransport_urllib
 
245
 
 
246
    def test_has(self):
 
247
        server = self.get_readonly_server()
 
248
        t = self._transport(server.get_url())
 
249
        self.assertRaises(ConnectionError, t.has, 'foo/bar')