~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-10-10 07:23:07 UTC
  • mfrom: (2067.1.1 urandom-56883)
  • Revision ID: pqm@pqm.ubuntu.com-20061010072307-037a6f63da8a1bdd
(John Arbash Meinel) Handle exceptions while opening /dev/urandom

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