~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http_response.py

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
146
146
 
147
147
    def test_content_type_re(self):
148
148
        self.regex = response.HttpMultipartRangeResponse._CONTENT_TYPE_RE
149
 
        self.assertRegexMatches(('xxyyzz',),
 
149
        self.assertRegexMatches(('', 'xxyyzz'),
150
150
                                'multipart/byteranges; boundary = xxyyzz')
151
 
        self.assertRegexMatches(('xxyyzz',),
 
151
        self.assertRegexMatches(('', 'xxyyzz'),
152
152
                                'multipart/byteranges;boundary=xxyyzz')
153
 
        self.assertRegexMatches(('xx yy zz',),
 
153
        self.assertRegexMatches(('', 'xx yy zz'),
154
154
                                ' multipart/byteranges ; boundary= xx yy zz ')
 
155
        self.assertRegexMatches(('"', 'xx yy zz'),
 
156
                                ' multipart/byteranges ; boundary= "xx yy zz" ')
 
157
        self.assertEqual(None,
 
158
                         self.regex.match(
 
159
                             ' multipart/byteranges ; boundary= "xx yy zz '))
 
160
        self.assertEqual(None,
 
161
                         self.regex.match(
 
162
                             ' multipart/byteranges ; boundary= xx yy zz" '))
155
163
        self.assertEqual(None,
156
164
                self.regex.match('multipart byteranges;boundary=xx'))
157
165
 
343
351
mbp@sourcefrog.net-20050309040929-eee0eb3e6d1e762""")
344
352
 
345
353
 
 
354
_single_range_no_content_type = (206, """HTTP/1.1 206 Partial Content\r
 
355
Date: Tue, 11 Jul 2006 04:45:22 GMT\r
 
356
Server: Apache/2.0.54 (Fedora)\r
 
357
Last-Modified: Thu, 06 Jul 2006 20:22:05 GMT\r
 
358
ETag: "238a3c-16ec2-805c5540"\r
 
359
Accept-Ranges: bytes\r
 
360
Content-Length: 100\r
 
361
Content-Range: bytes 100-199/93890\r
 
362
Connection: close\r
 
363
\r
 
364
""", """mbp@sourcefrog.net-20050309040815-13242001617e4a06
 
365
mbp@sourcefrog.net-20050309040929-eee0eb3e6d1e762""")
 
366
 
 
367
 
346
368
_multipart_range_response = (206, """HTTP/1.1 206 Partial Content\r
347
369
Date: Tue, 11 Jul 2006 04:49:48 GMT\r
348
370
Server: Apache/2.0.54 (Fedora)\r
389
411
mbp@sourcefrog.net-20050314025737-55eb441f430ab4ba
390
412
mbp@sourcefrog.net-20050314025901-d74aa93bb7ee8f62
391
413
mbp@source\r
392
 
--418470f848b63279b--\r\n'
 
414
--418470f848b63279b--\r
 
415
""")
 
416
 
 
417
_multipart_squid_range_response = (206, """HTTP/1.0 206 Partial Content\r
 
418
Date: Thu, 31 Aug 2006 21:16:22 GMT\r
 
419
Server: Apache/2.2.2 (Unix) DAV/2\r
 
420
Last-Modified: Thu, 31 Aug 2006 17:57:06 GMT\r
 
421
Accept-Ranges: bytes\r
 
422
Content-Type: multipart/byteranges; boundary="squid/2.5.STABLE12:C99323425AD4FE26F726261FA6C24196"\r
 
423
Content-Length: 598\r
 
424
X-Cache: MISS from localhost.localdomain\r
 
425
X-Cache-Lookup: HIT from localhost.localdomain:3128\r
 
426
Proxy-Connection: keep-alive\r
 
427
\r
 
428
""",
 
429
"""\r
 
430
--squid/2.5.STABLE12:C99323425AD4FE26F726261FA6C24196\r
 
431
Content-Type: text/plain\r
 
432
Content-Range: bytes 0-99/18672\r
 
433
\r
 
434
# bzr knit index 8
 
435
 
 
436
scott@netsplit.com-20050708230047-47c7868f276b939f fulltext 0 863  :
 
437
scott@netsp\r
 
438
--squid/2.5.STABLE12:C99323425AD4FE26F726261FA6C24196\r
 
439
Content-Type: text/plain\r
 
440
Content-Range: bytes 300-499/18672\r
 
441
\r
 
442
com-20050708231537-2b124b835395399a :
 
443
scott@netsplit.com-20050820234126-551311dbb7435b51 line-delta 1803 479 .scott@netsplit.com-20050820232911-dc4322a084eadf7e :
 
444
scott@netsplit.com-20050821213706-c86\r
 
445
--squid/2.5.STABLE12:C99323425AD4FE26F726261FA6C24196--\r
393
446
""")
394
447
 
395
448
 
469
522
        self.check_header('Content-Range', 'bytes 100-199/93890')
470
523
        self.check_header('Content-Type', 'text/plain; charset=UTF-8')
471
524
 
 
525
    def test_single_range_no_content(self):
 
526
        self.use_response(_single_range_no_content_type)
 
527
 
 
528
        self.check_header('Content-Length', '100')
 
529
        self.check_header('Content-Range', 'bytes 100-199/93890')
 
530
 
472
531
    def test_multi_range(self):
473
532
        self.use_response(_multipart_range_response)
474
533
 
476
535
        self.check_header('Content-Type',
477
536
                          'multipart/byteranges; boundary=418470f848b63279b')
478
537
 
 
538
    def test_multi_squid_range(self):
 
539
        self.use_response(_multipart_squid_range_response)
 
540
 
 
541
        self.check_header('Content-Length', '598')
 
542
        self.check_header('Content-Type',
 
543
                          'multipart/byteranges; '\
 
544
                          'boundary="squid/2.5.STABLE12:C99323425AD4FE26F726261FA6C24196"')
 
545
 
479
546
    def test_redirect(self):
480
547
        """We default to returning the last group of headers in the file."""
481
548
        self.use_response(_redirect_response)
550
617
        out.seek(100)
551
618
        self.assertEqual(_single_range_response[2], out.read(100))
552
619
 
 
620
    def test_single_range_no_content(self):
 
621
        out = self.get_response(_single_range_no_content_type)
 
622
        self.assertIsInstance(out, response.HttpRangeResponse)
 
623
 
 
624
        self.assertRaises(errors.InvalidRange, out.read, 20)
 
625
 
 
626
        out.seek(100)
 
627
        self.assertEqual(_single_range_no_content_type[2], out.read(100))
 
628
 
553
629
    def test_multi_range(self):
554
630
        out = self.get_response(_multipart_range_response)
555
631
        self.assertIsInstance(out, response.HttpMultipartRangeResponse)
561
637
        out.seek(1000)
562
638
        out.read(1050)
563
639
 
 
640
    def test_multi_squid_range(self):
 
641
        out = self.get_response(_multipart_squid_range_response)
 
642
        self.assertIsInstance(out, response.HttpMultipartRangeResponse)
 
643
 
 
644
        # Just make sure we can read the right contents
 
645
        out.seek(0)
 
646
        out.read(100)
 
647
 
 
648
        out.seek(300)
 
649
        out.read(200)
 
650
 
564
651
    def test_invalid_response(self):
565
652
        self.assertRaises(errors.InvalidHttpResponse,
566
653
            self.get_response, _invalid_response)
583
670
            response.handle_response, 'http://missing', a_response[0], headers,
584
671
                                      StringIO(a_response[2]))
585
672
 
586
 
    def test_missing_content_type(self):
587
 
        a_response = _single_range_response
588
 
        headers = http._extract_headers(a_response[1], 'http://nocontent')
589
 
        del headers['Content-Type']
590
 
        self.assertRaises(errors.InvalidHttpContentType,
591
 
            response.handle_response, 'http://nocontent', a_response[0],
592
 
                                      headers, StringIO(a_response[2]))
593
 
 
594
673
    def test_missing_content_range(self):
595
674
        a_response = _single_range_response
596
675
        headers = http._extract_headers(a_response[1], 'http://nocontent')