~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-07-19 20:32:38 UTC
  • mfrom: (1786.1.43 http)
  • Revision ID: pqm@pqm.ubuntu.com-20060719203238-892f369155dca5dc
(jam, mpee, jrydberg) update http with keep-alive and multi-range requests. http operations 2-4x faster

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib.errors import DependencyNotPresent
24
24
from bzrlib.tests import TestCase, TestSkipped
25
25
from bzrlib.transport import Transport
26
 
from bzrlib.transport.http import extract_auth
 
26
from bzrlib.transport.http import extract_auth, HttpTransportBase
27
27
from bzrlib.transport.http._urllib import HttpTransport_urllib
28
28
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
29
29
 
 
30
 
30
31
class FakeManager (object):
 
32
 
31
33
    def __init__(self):
32
34
        self.credentials = []
33
35
        
36
38
 
37
39
 
38
40
class TestHttpUrls(TestCase):
 
41
 
39
42
    def test_url_parsing(self):
40
43
        f = FakeManager()
41
44
        url = extract_auth('http://example.com', f)
90
93
        except DependencyNotPresent:
91
94
            raise TestSkipped('pycurl not present')
92
95
 
 
96
 
93
97
class TestHttpMixins(object):
94
98
 
95
99
    def _prep_tree(self):
124
128
 
125
129
 
126
130
class TestHttpConnections_urllib(TestCaseWithWebserver, TestHttpMixins):
 
131
 
127
132
    _transport = HttpTransport_urllib
128
133
 
129
134
    def setUp(self):
159
164
        t = get_transport('http+urllib://bzr.google.com/')
160
165
        self.assertIsInstance(t, Transport)
161
166
        self.assertIsInstance(t, bzrlib.transport.http._urllib.HttpTransport_urllib)
 
167
 
 
168
 
 
169
class TestOffsets(TestCase):
 
170
    """Test offsets_to_ranges method"""
 
171
 
 
172
    def test_offsets_to_ranges_simple(self):
 
173
        to_range = HttpTransportBase.offsets_to_ranges
 
174
        ranges = to_range([(10, 1)])
 
175
        self.assertEqual([[10, 10]], ranges)
 
176
 
 
177
        ranges = to_range([(0, 1), (1, 1)])
 
178
        self.assertEqual([[0, 1]], ranges)
 
179
 
 
180
        ranges = to_range([(1, 1), (0, 1)])
 
181
        self.assertEqual([[0, 1]], ranges)
 
182
 
 
183
    def test_offset_to_ranges_overlapped(self):
 
184
        to_range = HttpTransportBase.offsets_to_ranges
 
185
 
 
186
        ranges = to_range([(10, 1), (20, 2), (22, 5)])
 
187
        self.assertEqual([[10, 10], [20, 26]], ranges)
 
188
 
 
189
        ranges = to_range([(10, 1), (11, 2), (22, 5)])
 
190
        self.assertEqual([[10, 12], [22, 26]], ranges)
 
191
 
 
192
 
 
193
class TestRangeHeader(TestCase):
 
194
    """Test range_header method"""
 
195
 
 
196
    def check_header(self, value, ranges=[], tail=0):
 
197
        range_header = HttpTransportBase.range_header
 
198
        self.assertEqual(value, range_header(ranges, tail))
 
199
 
 
200
    def test_range_header_single(self):
 
201
        self.check_header('0-9', ranges=[[0,9]])
 
202
        self.check_header('100-109', ranges=[[100,109]])
 
203
 
 
204
    def test_range_header_tail(self):
 
205
        self.check_header('-10', tail=10)
 
206
        self.check_header('-50', tail=50)
 
207
 
 
208
    def test_range_header_multi(self):
 
209
        self.check_header('0-9,100-200,300-5000',
 
210
                          ranges=[(0,9), (100, 200), (300,5000)])
 
211
 
 
212
    def test_range_header_mixed(self):
 
213
        self.check_header('0-9,300-5000,-50',
 
214
                          ranges=[(0,9), (300,5000)],
 
215
                          tail=50)