@@ -51,6 +51,10 @@ def test_block_size_default(self):
51
51
""" Tests COMPRESS_BR_BLOCK default value is correctly set. """
52
52
self .assertEqual (self .app .config ['COMPRESS_BR_BLOCK' ], 0 )
53
53
54
+ def test_stream (self ):
55
+ """ Tests COMPRESS_STREAMS default value is correctly set. """
56
+ self .assertEqual (self .app .config ['COMPRESS_STREAMS' ], True )
57
+
54
58
class InitTests (unittest .TestCase ):
55
59
def setUp (self ):
56
60
self .app = Flask (__name__ )
@@ -353,13 +357,12 @@ class StreamTests(unittest.TestCase):
353
357
def setUp (self ):
354
358
self .app = Flask (__name__ )
355
359
self .app .testing = True
360
+ self .app .config ["COMPRESS_STREAMS" ] = False
356
361
357
362
self .file_path = os .path .join (os .getcwd (), 'tests' , 'templates' ,
358
363
'large.html' )
359
364
self .file_size = os .path .getsize (self .file_path )
360
365
361
- Compress (self .app )
362
-
363
366
@self .app .route ('/stream/large' )
364
367
def stream ():
365
368
def _stream ():
@@ -370,6 +373,7 @@ def _stream():
370
373
371
374
def test_no_compression_stream (self ):
372
375
""" Tests compression is skipped when response is streamed"""
376
+ Compress (self .app )
373
377
client = self .app .test_client ()
374
378
for algorithm in ('gzip' , 'deflate' , 'br' , '' ):
375
379
headers = [('Accept-Encoding' , algorithm )]
@@ -378,6 +382,17 @@ def test_no_compression_stream(self):
378
382
self .assertEqual (response .is_streamed , True )
379
383
self .assertEqual (self .file_size , len (response .data ))
380
384
385
+ def test_disabled_stream (self ):
386
+ """Test that stream compression can be disabled."""
387
+ Compress (self .app )
388
+ self .app .config ["COMPRESS_STREAMS" ] = True
389
+ client = self .app .test_client ()
390
+ for algorithm in ('gzip' , 'deflate' , 'br' ):
391
+ headers = [('Accept-Encoding' , algorithm )]
392
+ response = client .get ('/stream/large' , headers = headers )
393
+ self .assertIn ('Content-Encoding' , response .headers )
394
+ self .assertGreater (self .file_size , len (response .data ))
395
+
381
396
382
397
if __name__ == '__main__' :
383
398
unittest .main ()
0 commit comments