~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: 2011-03-08 16:59:36 UTC
  • mfrom: (5705.1.2 731240-range-parsing)
  • Revision ID: pqm@pqm.ubuntu.com-20110308165936-hp3voq41wvr83wnl
(vila) Correctly parse partial range specifiers in the HTTP test server.
 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
255
255
        self.assertEqual('realm="Thou should not pass"', remainder)
256
256
 
257
257
 
 
258
class TestHTTPRangeParsing(tests.TestCase):
 
259
 
 
260
    def setUp(self):
 
261
        super(TestHTTPRangeParsing, self).setUp()
 
262
        # We focus on range  parsing here and ignore everything else
 
263
        class RequestHandler(http_server.TestingHTTPRequestHandler):
 
264
            def setup(self): pass
 
265
            def handle(self): pass
 
266
            def finish(self): pass
 
267
 
 
268
        self.req_handler = RequestHandler(None, None, None)
 
269
 
 
270
    def assertRanges(self, ranges, header, file_size):
 
271
        self.assertEquals(ranges,
 
272
                          self.req_handler._parse_ranges(header, file_size))
 
273
 
 
274
    def test_simple_range(self):
 
275
        self.assertRanges([(0,2)], 'bytes=0-2', 12)
 
276
 
 
277
    def test_tail(self):
 
278
        self.assertRanges([(8, 11)], 'bytes=-4', 12)
 
279
 
 
280
    def test_tail_bigger_than_file(self):
 
281
        self.assertRanges([(0, 11)], 'bytes=-99', 12)
 
282
 
 
283
    def test_range_without_end(self):
 
284
        self.assertRanges([(4, 11)], 'bytes=4-', 12)
 
285
 
 
286
    def test_invalid_ranges(self):
 
287
        self.assertRanges(None, 'bytes=12-22', 12)
 
288
        self.assertRanges(None, 'bytes=1-3,12-22', 12)
 
289
        self.assertRanges(None, 'bytes=-', 12)
 
290
 
 
291
 
258
292
class TestHTTPServer(tests.TestCase):
259
293
    """Test the HTTP servers implementations."""
260
294
 
428
462
    """Test the http connections."""
429
463
 
430
464
    scenarios = multiply_scenarios(
431
 
        vary_by_http_client_implementation(), 
 
465
        vary_by_http_client_implementation(),
432
466
        vary_by_http_protocol_version(),
433
467
        )
434
468
 
493
527
class TestPost(tests.TestCase):
494
528
 
495
529
    scenarios = multiply_scenarios(
496
 
        vary_by_http_client_implementation(), 
 
530
        vary_by_http_client_implementation(),
497
531
        vary_by_http_protocol_version(),
498
532
        )
499
533
 
552
586
    """
553
587
 
554
588
    scenarios = multiply_scenarios(
555
 
        vary_by_http_client_implementation(), 
 
589
        vary_by_http_client_implementation(),
556
590
        vary_by_http_protocol_version(),
557
591
        )
558
592
 
1030
1064
    """Tests readv requests against a server erroring out on too much ranges."""
1031
1065
 
1032
1066
    scenarios = multiply_scenarios(
1033
 
        vary_by_http_client_implementation(), 
 
1067
        vary_by_http_client_implementation(),
1034
1068
        vary_by_http_protocol_version(),
1035
1069
        )
1036
1070
 
1076
1110
 
1077
1111
    def _proxied_request(self):
1078
1112
        handler = _urllib2_wrappers.ProxyHandler()
1079
 
        request = _urllib2_wrappers.Request('GET','http://baz/buzzle')
 
1113
        request = _urllib2_wrappers.Request('GET', 'http://baz/buzzle')
1080
1114
        handler.set_proxy(request, 'http')
1081
1115
        return request
1082
1116
 
1090
1124
        request = self._proxied_request()
1091
1125
        self.assertFalse(request.headers.has_key('Proxy-authorization'))
1092
1126
 
 
1127
    def test_user_with_at(self):
 
1128
        self.overrideEnv('http_proxy',
 
1129
                         'http://username@domain:password@proxy_host:1234')
 
1130
        request = self._proxied_request()
 
1131
        self.assertFalse(request.headers.has_key('Proxy-authorization'))
 
1132
 
1093
1133
    def test_invalid_proxy(self):
1094
1134
        """A proxy env variable without scheme"""
1095
1135
        self.overrideEnv('http_proxy', 'host:1234')
1126
1166
    """
1127
1167
 
1128
1168
    scenarios = multiply_scenarios(
1129
 
        vary_by_http_client_implementation(), 
 
1169
        vary_by_http_client_implementation(),
1130
1170
        vary_by_http_protocol_version(),
1131
1171
        )
1132
1172
 
1223
1263
    """Test the Range header in GET methods."""
1224
1264
 
1225
1265
    scenarios = multiply_scenarios(
1226
 
        vary_by_http_client_implementation(), 
 
1266
        vary_by_http_client_implementation(),
1227
1267
        vary_by_http_protocol_version(),
1228
1268
        )
1229
1269
 
1273
1313
    """Test redirection between http servers."""
1274
1314
 
1275
1315
    scenarios = multiply_scenarios(
1276
 
        vary_by_http_client_implementation(), 
 
1316
        vary_by_http_client_implementation(),
1277
1317
        vary_by_http_protocol_version(),
1278
1318
        )
1279
1319
 
1346
1386
    """
1347
1387
 
1348
1388
    scenarios = multiply_scenarios(
1349
 
        vary_by_http_client_implementation(), 
 
1389
        vary_by_http_client_implementation(),
1350
1390
        vary_by_http_protocol_version(),
1351
1391
        )
1352
1392
 
1401
1441
    """Test transport.do_catching_redirections."""
1402
1442
 
1403
1443
    scenarios = multiply_scenarios(
1404
 
        vary_by_http_client_implementation(), 
 
1444
        vary_by_http_client_implementation(),
1405
1445
        vary_by_http_protocol_version(),
1406
1446
        )
1407
1447
 
1756
1796
class SmartHTTPTunnellingTest(tests.TestCaseWithTransport):
1757
1797
 
1758
1798
    scenarios = multiply_scenarios(
1759
 
        vary_by_http_client_implementation(), 
 
1799
        vary_by_http_client_implementation(),
1760
1800
        vary_by_http_protocol_version(),
1761
1801
        )
1762
1802