~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

Late bind to PatienceSequenceMatcher to allow plugin to override.

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, 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
29
29
 
30
 
 
31
30
class FakeManager (object):
32
 
 
33
31
    def __init__(self):
34
32
        self.credentials = []
35
33
        
38
36
 
39
37
 
40
38
class TestHttpUrls(TestCase):
41
 
 
42
39
    def test_url_parsing(self):
43
40
        f = FakeManager()
44
41
        url = extract_auth('http://example.com', f)
93
90
        except DependencyNotPresent:
94
91
            raise TestSkipped('pycurl not present')
95
92
 
96
 
 
97
93
class TestHttpMixins(object):
98
94
 
99
95
    def _prep_tree(self):
128
124
 
129
125
 
130
126
class TestHttpConnections_urllib(TestCaseWithWebserver, TestHttpMixins):
131
 
 
132
127
    _transport = HttpTransport_urllib
133
128
 
134
129
    def setUp(self):
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)
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)