File: test_gzipper.py

package info (click to toggle)
paste 3.5.2%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,424 kB
  • sloc: python: 18,933; javascript: 8,028; sh: 24; makefile: 16
file content (27 lines) | stat: -rw-r--r-- 888 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from paste.fixture import TestApp
from paste.gzipper import middleware
import gzip
import six

def simple_app(environ, start_response):
    start_response('200 OK',
                   [('content-type', 'text/plain'),
                    ('content-length', '0')])
    return [b'this is a test'] if environ['REQUEST_METHOD'] != 'HEAD' else []

wsgi_app = middleware(simple_app)
app = TestApp(wsgi_app)

def test_gzip():
    res = app.get(
        '/', extra_environ=dict(HTTP_ACCEPT_ENCODING='gzip'))
    assert int(res.header('content-length')) == len(res.body)
    assert res.body != b'this is a test'
    actual = gzip.GzipFile(fileobj=six.BytesIO(res.body)).read()
    assert actual == b'this is a test'

def test_gzip_head():
    res = app.head(
        '/', extra_environ=dict(HTTP_ACCEPT_ENCODING='gzip'))
    assert int(res.header('content-length')) == 0
    assert res.body == b''