~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http_response.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

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
351
351
mbp@sourcefrog.net-20050309040929-eee0eb3e6d1e762""")
352
352
 
353
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
 
354
368
_multipart_range_response = (206, """HTTP/1.1 206 Partial Content\r
355
369
Date: Tue, 11 Jul 2006 04:49:48 GMT\r
356
370
Server: Apache/2.0.54 (Fedora)\r
508
522
        self.check_header('Content-Range', 'bytes 100-199/93890')
509
523
        self.check_header('Content-Type', 'text/plain; charset=UTF-8')
510
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
 
511
531
    def test_multi_range(self):
512
532
        self.use_response(_multipart_range_response)
513
533
 
597
617
        out.seek(100)
598
618
        self.assertEqual(_single_range_response[2], out.read(100))
599
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
 
600
629
    def test_multi_range(self):
601
630
        out = self.get_response(_multipart_range_response)
602
631
        self.assertIsInstance(out, response.HttpMultipartRangeResponse)
641
670
            response.handle_response, 'http://missing', a_response[0], headers,
642
671
                                      StringIO(a_response[2]))
643
672
 
644
 
    def test_missing_content_type(self):
645
 
        a_response = _single_range_response
646
 
        headers = http._extract_headers(a_response[1], 'http://nocontent')
647
 
        del headers['Content-Type']
648
 
        self.assertRaises(errors.InvalidHttpContentType,
649
 
            response.handle_response, 'http://nocontent', a_response[0],
650
 
                                      headers, StringIO(a_response[2]))
651
 
 
652
673
    def test_missing_content_range(self):
653
674
        a_response = _single_range_response
654
675
        headers = http._extract_headers(a_response[1], 'http://nocontent')