~ubuntu-branches/ubuntu/trusty/python-urllib3/trusty-proposed

« back to all changes in this revision

Viewing changes to test/test_response.py

  • Committer: Package Import Robot
  • Author(s): Daniele Tricoli, Jakub Wilk, Daniele Tricoli
  • Date: 2013-05-11 15:15:38 UTC
  • mfrom: (1.2.1) (4.2.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20130511151538-4dshl34jt0kkpt9i
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Daniele Tricoli ]
* New upstream release
* Upload to unstable (Closes: #707780)
* debian/control
  - Added python3-six to Build-Depends field
  - Bumped debhelper dependency to 8.1 for build-{arch,indep} support
  - Removed python-setuptools from Build-Depends field
* debian/copyright
  - Updated copyright years
  - Added stanza for urllib3/packages/ordered_dict.py
* debian/patches/01_do-not-use-embedded-python-six.patch
  - Refreshed
* debian/patches/02_require-cert-verification.patch
  - Refreshed
* debian/patches/03_no-setuptools.patch
  - Do not use setuptools
* debian/patches/04_relax_nosetests_options.patch
  - Do not use logging-clear-handlers to see all logging output and
    disabled cover-min-percentage since it require python-nose (>= 1.3):
    this way it will be easier to backport python-urllib3 to Wheezy.
* debian/patches/05_fix_python3_syntax_error_in_ntlmpool.patch
  - Fix syntax error 'unicodeescape' codec can't decode bytes in
    position 130-132 for Python3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import unittest
2
 
import zlib
3
2
 
4
3
from io import BytesIO
5
4
 
6
5
from urllib3.response import HTTPResponse
 
6
from urllib3.exceptions import DecodeError
7
7
 
8
8
class TestLegacyResponse(unittest.TestCase):
9
9
    def test_getheaders(self):
50
50
 
51
51
    def test_decode_bad_data(self):
52
52
        fp = BytesIO(b'\x00' * 10)
53
 
        self.assertRaises(zlib.error, HTTPResponse, fp, headers={
 
53
        self.assertRaises(DecodeError, HTTPResponse, fp, headers={
54
54
            'content-encoding': 'deflate'
55
55
        })
56
56
 
63
63
 
64
64
        self.assertEqual(r.data, b'foo')
65
65
 
 
66
    def test_decode_deflate_case_insensitve(self):
 
67
        import zlib
 
68
        data = zlib.compress(b'foo')
 
69
 
 
70
        fp = BytesIO(data)
 
71
        r = HTTPResponse(fp, headers={'content-encoding': 'DeFlAtE'})
 
72
 
 
73
        self.assertEqual(r.data, b'foo')
 
74
 
 
75
    def test_chunked_decoding_deflate(self):
 
76
        import zlib
 
77
        data = zlib.compress(b'foo')
 
78
 
 
79
        fp = BytesIO(data)
 
80
        r = HTTPResponse(fp, headers={'content-encoding': 'deflate'},
 
81
                         preload_content=False)
 
82
 
 
83
        self.assertEqual(r.read(3), b'')
 
84
        self.assertEqual(r.read(1), b'f')
 
85
        self.assertEqual(r.read(2), b'oo')
 
86
 
 
87
    def test_chunked_decoding_deflate2(self):
 
88
        import zlib
 
89
        compress = zlib.compressobj(6, zlib.DEFLATED, -zlib.MAX_WBITS)
 
90
        data = compress.compress(b'foo')
 
91
        data += compress.flush()
 
92
 
 
93
        fp = BytesIO(data)
 
94
        r = HTTPResponse(fp, headers={'content-encoding': 'deflate'},
 
95
                         preload_content=False)
 
96
 
 
97
        self.assertEqual(r.read(1), b'')
 
98
        self.assertEqual(r.read(1), b'f')
 
99
        self.assertEqual(r.read(2), b'oo')
 
100
 
 
101
    def test_chunked_decoding_gzip(self):
 
102
        import zlib
 
103
        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
 
104
        data = compress.compress(b'foo')
 
105
        data += compress.flush()
 
106
 
 
107
        fp = BytesIO(data)
 
108
        r = HTTPResponse(fp, headers={'content-encoding': 'gzip'},
 
109
                         preload_content=False)
 
110
 
 
111
        self.assertEqual(r.read(11), b'')
 
112
        self.assertEqual(r.read(1), b'f')
 
113
        self.assertEqual(r.read(2), b'oo')
66
114
 
67
115
if __name__ == '__main__':
68
116
    unittest.main()