~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http_response.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-17 07:52:09 UTC
  • mfrom: (1910.3.4 trivial)
  • Revision ID: pqm@pqm.ubuntu.com-20060817075209-e85a1f9e05ff8b87
(andrew) Trivial fixes to NotImplemented errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by 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" '))
163
155
        self.assertEqual(None,
164
156
                self.regex.match('multipart byteranges;boundary=xx'))
165
157
 
351
343
mbp@sourcefrog.net-20050309040929-eee0eb3e6d1e762""")
352
344
 
353
345
 
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
 
 
368
346
_multipart_range_response = (206, """HTTP/1.1 206 Partial Content\r
369
347
Date: Tue, 11 Jul 2006 04:49:48 GMT\r
370
348
Server: Apache/2.0.54 (Fedora)\r
411
389
mbp@sourcefrog.net-20050314025737-55eb441f430ab4ba
412
390
mbp@sourcefrog.net-20050314025901-d74aa93bb7ee8f62
413
391
mbp@source\r
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
 
392
--418470f848b63279b--\r\n'
446
393
""")
447
394
 
448
395
 
522
469
        self.check_header('Content-Range', 'bytes 100-199/93890')
523
470
        self.check_header('Content-Type', 'text/plain; charset=UTF-8')
524
471
 
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
 
 
531
472
    def test_multi_range(self):
532
473
        self.use_response(_multipart_range_response)
533
474
 
535
476
        self.check_header('Content-Type',
536
477
                          'multipart/byteranges; boundary=418470f848b63279b')
537
478
 
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
 
 
546
479
    def test_redirect(self):
547
480
        """We default to returning the last group of headers in the file."""
548
481
        self.use_response(_redirect_response)
617
550
        out.seek(100)
618
551
        self.assertEqual(_single_range_response[2], out.read(100))
619
552
 
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
 
 
629
553
    def test_multi_range(self):
630
554
        out = self.get_response(_multipart_range_response)
631
555
        self.assertIsInstance(out, response.HttpMultipartRangeResponse)
637
561
        out.seek(1000)
638
562
        out.read(1050)
639
563
 
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
 
 
651
564
    def test_invalid_response(self):
652
565
        self.assertRaises(errors.InvalidHttpResponse,
653
566
            self.get_response, _invalid_response)
670
583
            response.handle_response, 'http://missing', a_response[0], headers,
671
584
                                      StringIO(a_response[2]))
672
585
 
 
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
 
673
594
    def test_missing_content_range(self):
674
595
        a_response = _single_range_response
675
596
        headers = http._extract_headers(a_response[1], 'http://nocontent')