/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_http_response.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
  InvalidHttpResponse.
38
38
"""
39
39
 
40
 
try:
41
 
    import http.client as http_client
42
 
    parse_headers = http_client.parse_headers
43
 
except ImportError:  # python < 3
44
 
    import httplib as http_client
45
 
    parse_headers = http_client.HTTPMessage
 
40
from io import BytesIO
 
41
 
 
42
import http.client as http_client
 
43
 
 
44
parse_headers = http_client.parse_headers
46
45
 
47
46
from .. import (
48
47
    errors,
49
48
    tests,
50
49
    )
51
 
from ..sixish import (
52
 
    BytesIO,
53
 
    )
54
50
from ..transport.http import (
55
51
    response,
56
 
    _urllib2_wrappers,
 
52
    HTTPConnection,
57
53
    )
58
54
from .file_utils import (
59
55
    FakeReadFile,
70
66
        return self.readfile
71
67
 
72
68
 
73
 
class FakeHTTPConnection(_urllib2_wrappers.HTTPConnection):
 
69
class FakeHTTPConnection(HTTPConnection):
74
70
 
75
71
    def __init__(self, sock):
76
 
        _urllib2_wrappers.HTTPConnection.__init__(self, 'localhost')
 
72
        HTTPConnection.__init__(self, 'localhost')
77
73
        # Set the socket to bypass the connection
78
74
        self.sock = sock
79
75
 
92
88
        f = response.ResponseFile('many', BytesIO(b'0\n1\nboo!\n'))
93
89
        self.assertEqual([b'0\n', b'1\n', b'boo!\n'], list(f))
94
90
 
 
91
    def test_readlines(self):
 
92
        f = response.ResponseFile('many', BytesIO(b'0\n1\nboo!\n'))
 
93
        self.assertEqual([b'0\n', b'1\n', b'boo!\n'], f.readlines())
 
94
 
95
95
 
96
96
class TestHTTPConnection(tests.TestCase):
97
97
 
722
722
        # Get rid of the status line
723
723
        status_and_headers.readline()
724
724
        msg = parse_headers(status_and_headers)
725
 
        return msg
 
725
        return msg.get
726
726
 
727
727
    def get_response(self, a_response):
728
728
        """Process a supplied response, and return the result."""
729
729
        code, raw_headers, body = a_response
730
 
        msg = self._build_HTTPMessage(raw_headers)
731
 
        return response.handle_response('http://foo', code, msg,
732
 
                                        BytesIO(a_response[2]))
 
730
        getheader = self._build_HTTPMessage(raw_headers)
 
731
        return response.handle_response(
 
732
            'http://foo', code, getheader, BytesIO(a_response[2]))
733
733
 
734
734
    def test_full_text(self):
735
735
        out = self.get_response(_full_text_response)
780
780
    def test_full_text_no_content_type(self):
781
781
        # We should not require Content-Type for a full response
782
782
        code, raw_headers, body = _full_text_response_no_content_type
783
 
        msg = self._build_HTTPMessage(raw_headers)
784
 
        out = response.handle_response('http://foo', code, msg, BytesIO(body))
 
783
        getheader = self._build_HTTPMessage(raw_headers)
 
784
        out = response.handle_response(
 
785
            'http://foo', code, getheader, BytesIO(body))
785
786
        self.assertEqual(body, out.read())
786
787
 
787
788
    def test_full_text_no_content_length(self):
788
789
        code, raw_headers, body = _full_text_response_no_content_length
789
 
        msg = self._build_HTTPMessage(raw_headers)
790
 
        out = response.handle_response('http://foo', code, msg, BytesIO(body))
 
790
        getheader = self._build_HTTPMessage(raw_headers)
 
791
        out = response.handle_response(
 
792
            'http://foo', code, getheader, BytesIO(body))
791
793
        self.assertEqual(body, out.read())
792
794
 
793
795
    def test_missing_content_range(self):
794
796
        code, raw_headers, body = _single_range_no_content_range
795
 
        msg = self._build_HTTPMessage(raw_headers)
 
797
        getheader = self._build_HTTPMessage(raw_headers)
796
798
        self.assertRaises(errors.InvalidHttpResponse,
797
799
                          response.handle_response,
798
 
                          'http://bogus', code, msg, BytesIO(body))
 
800
                          'http://bogus', code, getheader, BytesIO(body))
799
801
 
800
802
    def test_multipart_no_content_range(self):
801
803
        code, raw_headers, body = _multipart_no_content_range
802
 
        msg = self._build_HTTPMessage(raw_headers)
 
804
        getheader = self._build_HTTPMessage(raw_headers)
803
805
        self.assertRaises(errors.InvalidHttpResponse,
804
806
                          response.handle_response,
805
 
                          'http://bogus', code, msg, BytesIO(body))
 
807
                          'http://bogus', code, getheader, BytesIO(body))
806
808
 
807
809
    def test_multipart_no_boundary(self):
808
810
        out = self.get_response(_multipart_no_boundary)