test_decoders.py
This file
Path
tests/test_decoders.py
88 lines · 2.7 KiB · Python
Last changed by
Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
History of this fileTake it
Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 1–5why, one step back1import zlib23import brotli4import pytest5Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 6why, one step back6import httpxRejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 7–14why, one step back789def test_deflate():10 body = b"test 123"11 compressor = zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS)12 compressed_body = compressor.compress(body) + compressor.flush()1314 headers = [(b"Content-Encoding", b"deflate")]Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 15why, one step back15 response = httpx.Response(200, headers=headers, content=compressed_body)Response.contentTom Christiebefore adoption4c55113
line 16why, one step back16 assert response.content == bodyRejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 17–24why, one step back171819def test_gzip():20 body = b"test 123"21 compressor = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS | 16)22 compressed_body = compressor.compress(body) + compressor.flush()2324 headers = [(b"Content-Encoding", b"gzip")]Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 25why, one step back25 response = httpx.Response(200, headers=headers, content=compressed_body)Response.contentTom Christiebefore adoption4c55113
line 26why, one step back26 assert response.content == bodyRejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 27–33why, one step back272829def test_brotli():30 body = b"test 123"31 compressed_body = brotli.compress(body)3233 headers = [(b"Content-Encoding", b"br")]Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 34why, one step back34 response = httpx.Response(200, headers=headers, content=compressed_body)Response.contentTom Christiebefore adoption4c55113
line 35why, one step back35 assert response.content == bodyRejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 36–49why, one step back363738def test_multi():39 body = b"test 123"4041 deflate_compressor = zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS)42 compressed_body = deflate_compressor.compress(body) + deflate_compressor.flush()4344 gzip_compressor = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS | 16)45 compressed_body = (46 gzip_compressor.compress(compressed_body) + gzip_compressor.flush()47 )4849 headers = [(b"Content-Encoding", b"deflate, gzip")]Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 50why, one step back50 response = httpx.Response(200, headers=headers, content=compressed_body)Response.contentTom Christiebefore adoption4c55113
line 51why, one step back51 assert response.content == bodyRejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 52–58why, one step back525354def test_multi_with_identity():55 body = b"test 123"56 compressed_body = brotli.compress(body)5758 headers = [(b"Content-Encoding", b"br, identity")]Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 59why, one step back59 response = httpx.Response(200, headers=headers, content=compressed_body)Response.contentTom Christiebefore adoption4c55113
line 60why, one step back60 assert response.content == bodyRejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 61–62why, one step back6162 headers = [(b"Content-Encoding", b"identity, br")]Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 63why, one step back63 response = httpx.Response(200, headers=headers, content=compressed_body)Response.contentTom Christiebefore adoption4c55113
line 64why, one step back64 assert response.content == bodyRejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 65–66why, one step back6566Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7
line 67why, one step back67def test_streaming():Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 68–70why, one step back68 body = b"test 123"69 compressor = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS | 16)70Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7
line 71why, one step back71 def compress(body):Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 72–75why, one step back72 yield compressor.compress(body)73 yield compressor.flush()7475 headers = [(b"Content-Encoding", b"gzip")]Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 76why, one step back76 response = httpx.Response(200, headers=headers, content=compress(body))Rejig test and tighten up models APITom Christiebefore adoptiondea4d42
line 77why, one step back77 assert not hasattr(response, "body")Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7
line 78why, one step back78 assert response.read() == bodyRejig test and tighten up models APITom Christiebefore adoptiondea4d42
lines 79–85why, one step back798081@pytest.mark.parametrize("header_value", (b"deflate", b"gzip", b"br"))82def test_decoding_errors(header_value):83 headers = [(b"Content-Encoding", header_value)]84 body = b"test 123"85 compressed_body = brotli.compress(body)[3:]Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
lines 86–87why, one step back86 with pytest.raises(httpx.exceptions.DecodingError):87 response = httpx.Response(200, headers=headers, content=compressed_body)Response.contentTom Christiebefore adoption4c55113
line 88why, one step back88 response.content