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, HttpTransportBase
26
from bzrlib.transport.http import extract_auth
27
27
from bzrlib.transport.http._urllib import HttpTransport_urllib
28
28
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
31
30
class FakeManager (object):
33
31
def __init__(self):
34
32
self.credentials = []
164
159
t = get_transport('http+urllib://bzr.google.com/')
165
160
self.assertIsInstance(t, Transport)
166
161
self.assertIsInstance(t, bzrlib.transport.http._urllib.HttpTransport_urllib)
169
class TestOffsets(TestCase):
170
"""Test offsets_to_ranges method"""
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)
177
ranges = to_range([(0, 1), (1, 1)])
178
self.assertEqual([[0, 1]], ranges)
180
ranges = to_range([(1, 1), (0, 1)])
181
self.assertEqual([[0, 1]], ranges)
183
def test_offset_to_ranges_overlapped(self):
184
to_range = HttpTransportBase.offsets_to_ranges
186
ranges = to_range([(10, 1), (20, 2), (22, 5)])
187
self.assertEqual([[10, 10], [20, 26]], ranges)
189
ranges = to_range([(10, 1), (11, 2), (22, 5)])
190
self.assertEqual([[10, 12], [22, 26]], ranges)
193
class TestRangeHeader(TestCase):
194
"""Test range_header method"""
196
def check_header(self, value, ranges=[], tail=0):
197
range_header = HttpTransportBase.range_header
198
self.assertEqual(value, range_header(ranges, tail))
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]])
204
def test_range_header_tail(self):
205
self.check_header('-10', tail=10)
206
self.check_header('-50', tail=50)
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)])
212
def test_range_header_mixed(self):
213
self.check_header('0-9,300-5000,-50',
214
ranges=[(0,9), (300,5000)],