/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2019-05-28 23:50:18 UTC
  • mfrom: (7296.2.9 urllib3-like)
  • Revision ID: breezy.the.bot@gmail.com-20190528235018-wpu2geti8rd2t9ji
Use a more urllib3-like API for HTTP requests.

Merged from https://code.launchpad.net/~jelmer/brz/urllib3-like/+merge/367618

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    )
54
54
from ..sixish import (
55
55
    BytesIO,
 
56
    PY3,
56
57
    )
57
58
from ..transport.http import (
58
59
    response,
725
726
        # Get rid of the status line
726
727
        status_and_headers.readline()
727
728
        msg = parse_headers(status_and_headers)
728
 
        return msg
 
729
        if PY3:
 
730
            return msg.get
 
731
        else:
 
732
            return msg.getheader
729
733
 
730
734
    def get_response(self, a_response):
731
735
        """Process a supplied response, and return the result."""
732
736
        code, raw_headers, body = a_response
733
 
        msg = self._build_HTTPMessage(raw_headers)
734
 
        return response.handle_response('http://foo', code, msg,
735
 
                                        BytesIO(a_response[2]))
 
737
        getheader = self._build_HTTPMessage(raw_headers)
 
738
        return response.handle_response(
 
739
            'http://foo', code, getheader, BytesIO(a_response[2]))
736
740
 
737
741
    def test_full_text(self):
738
742
        out = self.get_response(_full_text_response)
783
787
    def test_full_text_no_content_type(self):
784
788
        # We should not require Content-Type for a full response
785
789
        code, raw_headers, body = _full_text_response_no_content_type
786
 
        msg = self._build_HTTPMessage(raw_headers)
787
 
        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))
788
793
        self.assertEqual(body, out.read())
789
794
 
790
795
    def test_full_text_no_content_length(self):
791
796
        code, raw_headers, body = _full_text_response_no_content_length
792
 
        msg = self._build_HTTPMessage(raw_headers)
793
 
        out = response.handle_response('http://foo', code, msg, BytesIO(body))
 
797
        getheader = self._build_HTTPMessage(raw_headers)
 
798
        out = response.handle_response(
 
799
            'http://foo', code, getheader, BytesIO(body))
794
800
        self.assertEqual(body, out.read())
795
801
 
796
802
    def test_missing_content_range(self):
797
803
        code, raw_headers, body = _single_range_no_content_range
798
 
        msg = self._build_HTTPMessage(raw_headers)
 
804
        getheader = self._build_HTTPMessage(raw_headers)
799
805
        self.assertRaises(errors.InvalidHttpResponse,
800
806
                          response.handle_response,
801
 
                          'http://bogus', code, msg, BytesIO(body))
 
807
                          'http://bogus', code, getheader, BytesIO(body))
802
808
 
803
809
    def test_multipart_no_content_range(self):
804
810
        code, raw_headers, body = _multipart_no_content_range
805
 
        msg = self._build_HTTPMessage(raw_headers)
 
811
        getheader = self._build_HTTPMessage(raw_headers)
806
812
        self.assertRaises(errors.InvalidHttpResponse,
807
813
                          response.handle_response,
808
 
                          'http://bogus', code, msg, BytesIO(body))
 
814
                          'http://bogus', code, getheader, BytesIO(body))
809
815
 
810
816
    def test_multipart_no_boundary(self):
811
817
        out = self.get_response(_multipart_no_boundary)