~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-13 13:11:06 UTC
  • mto: This revision was merged to the branch mainline in revision 1869.
  • Revision ID: john@arbash-meinel.com-20060713131106-4f059a8003d852bd
Move offset_to_http_ranges back onto HttpTransportBase, clarify tests.

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
 
164
164
        t = get_transport('http+urllib://bzr.google.com/')
165
165
        self.assertIsInstance(t, Transport)
166
166
        self.assertIsInstance(t, bzrlib.transport.http._urllib.HttpTransport_urllib)
 
167
 
 
168
 
 
169
class TestOffsets(TestCase):
 
170
    """Test test_offsets_to_ranges method"""
 
171
 
 
172
    def test_offsets_to_ranges_simple(self):
 
173
        to_range = HttpTransportBase.offsets_to_ranges
 
174
        ranges, tail = to_range([(10, 1)])
 
175
        self.assertEqual([[10, 10]], ranges)
 
176
        self.assertEqual(0, tail)
 
177
 
 
178
        ranges, tail = to_range([(0, 1), (1, 1)])
 
179
        self.assertEqual([[0, 1]], ranges)
 
180
        self.assertEqual(0, tail)
 
181
 
 
182
        ranges, tail = to_range([(1, 1), (0, 1)])
 
183
        self.assertEqual([[0, 1]], ranges)
 
184
        self.assertEqual(0, tail)
 
185
 
 
186
    def test_offset_to_ranges_overlapped(self):
 
187
        to_range = HttpTransportBase.offsets_to_ranges
 
188
 
 
189
        ranges, tail = to_range([(10, 1), (20, 2), (22, 5)])
 
190
        self.assertEquals(tuple(ranges[0]), (10, 10))
 
191
        self.assertEquals(tuple(ranges[1]), (20, 26))
 
192
        self.assertEquals(tail, 0)
 
193
 
 
194
        ranges, tail = to_range([(10, 1), (11, 2), (22, 5), (-4, 4)])
 
195
        self.assertEquals(tuple(ranges[0]), (10, 12))
 
196
        self.assertEquals(tuple(ranges[1]), (22, 26))
 
197
        self.assertEquals(tail, 4)
 
198
 
 
199
    def test_offset_to_ranges_tail(self):
 
200
        to_range = HttpTransportBase.offsets_to_ranges
 
201
 
 
202
        ranges, tail = to_range([(-4, 4), (-8, 8)])
 
203
        self.assertEquals(tuple(ranges), ())
 
204
        self.assertEquals(tail, 8)
 
205
 
 
206
    def test_offset_to_ranges_fudge(self):
 
207
        to_range = HttpTransportBase.offsets_to_ranges
 
208
 
 
209
        ranges, tail = to_range([(10, 1), (20, 2)], fudge_factor=9)
 
210
        self.assertEquals(tuple(ranges[0]), (10, 21))
 
211
        self.assertEquals(len(ranges), 1)
 
212
        self.assertEquals(tail, 0)
 
213
 
 
214
        ranges, tail = to_range([(10, 1), (20, 2)], fudge_factor=8)
 
215
        self.assertEquals(tuple(ranges[0]), (10, 10))
 
216
        self.assertEquals(tuple(ranges[1]), (20, 21))
 
217
        self.assertEquals(tail, 0)
 
218