Skip to content
This repository

additional test for 100% coverage of pull request 85 #97

Closed
wants to merge 8 commits into from

4 participants

Tom Willis Rishi Ramraj Chris McDonough Tres Seaver
Tom Willis

No description provided.

Tom Willis twillis referenced this pull request March 19, 2013
Merged

ordering matters part 2 #96

tests/test_response.py
((5 lines not shown))
958 956
         b'K\xcb\xcf\x07\x00',
959 957
         b'!es\x8c\x03\x00\x00\x00'
960 958
         ])
961 959
 
  960
+def test_encode_content_gzip_buffer_coverage():
  961
+    """this test is to provide 100% coverage of
  962
+    response.Response.encode_content was necessary in order to get
  963
+    pull request https://github.com/Pylons/webob/pull/85 into upstream
  964
+    """
  965
+    res = Response()
  966
+    DATA = b"abcdefghijklmnopqrstuvwxyz0123456789" * 1000000
  967
+    res.app_iter = io.BytesIO(DATA)
  968
+    res.encode_content('gzip')
  969
+    result = list(res.app_iter)
  970
+    assert len(result) < DATA
2

Is this what you're going for?

assert len(''.join(result)) < len(DATA)
Tom Willis
twillis added a note March 19, 2013

hahahahah, yes you are right. damn it all :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Rishi Ramraj

+1 looking good!

Rishi Ramraj

I think you're still missing the len on data :)

assert len("".join(result)) < len(DATA)

i blame the time zone differences.

Chris McDonough
Owner

Sorry I hate to ask, but can somebody open up a new pull request with only the bugfixes for #85 (this one seems to contain fixes for #96 and I merged those already).

Tom Willis

yeah I'll do it sorry for the confusion

Tres Seaver
Owner

Closed via #98

Tres Seaver tseaver closed this March 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
27  tests/test_request.py
@@ -829,7 +829,12 @@ def test_blank__str_post_data_for_unsupported_ctype(self):
829 829
                           '/', content_type='application/json', POST={})
830 830
 
831 831
     def test_blank__post_urlencoded(self):
832  
-        request = self._blankOne('/', POST={'first':1, 'second':2})
  832
+        from webob.multidict import MultiDict
  833
+        POST = MultiDict()
  834
+        POST["first"] = 1
  835
+        POST["second"] = 2
  836
+
  837
+        request = self._blankOne('/', POST=POST)
833 838
         self.assertEqual(request.method, 'POST')
834 839
         self.assertEqual(request.content_type,
835 840
                          'application/x-www-form-urlencoded')
@@ -837,9 +842,15 @@ def test_blank__post_urlencoded(self):
837 842
         self.assertEqual(request.content_length, 16)
838 843
 
839 844
     def test_blank__post_multipart(self):
840  
-        request = self._blankOne(
841  
-            '/', POST={'first':'1', 'second':'2'},
842  
-            content_type='multipart/form-data; boundary=boundary')
  845
+        from webob.multidict import MultiDict
  846
+        POST = MultiDict()
  847
+        POST["first"] = "1"
  848
+        POST["second"] = "2"
  849
+
  850
+
  851
+        request = self._blankOne('/', 
  852
+                                 POST=POST,
  853
+                                 content_type='multipart/form-data; boundary=boundary')
843 854
         self.assertEqual(request.method, 'POST')
844 855
         self.assertEqual(request.content_type, 'multipart/form-data')
845 856
         expected = (
@@ -856,9 +867,11 @@ def test_blank__post_multipart(self):
856 867
     def test_blank__post_files(self):
857 868
         import cgi
858 869
         from webob.request import _get_multipart_boundary
859  
-        POST = {'first':('filename1', BytesIO(b'1')),
860  
-                       'second':('filename2', '2'),
861  
-                       'third': '3'}
  870
+        from webob.multidict import MultiDict
  871
+        POST = MultiDict()
  872
+        POST["first"] = ('filename1', BytesIO(b'1'))
  873
+        POST["second"] = ('filename2', '2')
  874
+        POST["third"] = "3"
862 875
         request = self._blankOne('/', POST=POST)
863 876
         self.assertEqual(request.method, 'POST')
864 877
         self.assertEqual(request.content_type, 'multipart/form-data')
14  tests/test_response.py
@@ -941,7 +941,6 @@ def test_encode_content_gzip_notyet_gzipped():
941 941
     eq_(res.content_length, 23)
942 942
     eq_(res.app_iter, [
943 943
         b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff',
944  
-        b'',
945 944
         b'K\xcb\xcf\x07\x00',
946 945
         b'!es\x8c\x03\x00\x00\x00'
947 946
         ])
@@ -954,11 +953,22 @@ def test_encode_content_gzip_notyet_gzipped_lazy():
954 953
     eq_(res.content_length, None)
955 954
     eq_(list(res.app_iter), [
956 955
         b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff',
957  
-        b'',
958 956
         b'K\xcb\xcf\x07\x00',
959 957
         b'!es\x8c\x03\x00\x00\x00'
960 958
         ])
961 959
 
  960
+def test_encode_content_gzip_buffer_coverage():
  961
+    """this test is to provide 100% coverage of
  962
+    response.Response.encode_content was necessary in order to get
  963
+    pull request https://github.com/Pylons/webob/pull/85 into upstream
  964
+    """
  965
+    res = Response()
  966
+    DATA = b"abcdefghijklmnopqrstuvwxyz0123456789" * 1000000
  967
+    res.app_iter = io.BytesIO(DATA)
  968
+    res.encode_content('gzip')
  969
+    result = list(res.app_iter)
  970
+    assert len("".join(result)) < len(DATA)
  971
+
962 972
 def test_decode_content_identity():
963 973
     res = Response()
964 974
     res.content_encoding = 'identity'
5  webob/request.py
@@ -1455,8 +1455,7 @@ def environ_add_POST(env, data, content_type=None):
1455 1455
         env['REQUEST_METHOD'] = 'POST'
1456 1456
     has_files = False
1457 1457
     if hasattr(data, 'items'):
1458  
-        data = sorted(data.items())
1459  
-        for k, v in data:
  1458
+        for k, v in data.items():
1460 1459
             if isinstance(v, (tuple, list)):
1461 1460
                 has_files = True
1462 1461
                 break
@@ -1467,7 +1466,7 @@ def environ_add_POST(env, data, content_type=None):
1467 1466
             content_type = 'application/x-www-form-urlencoded'
1468 1467
     if content_type.startswith('multipart/form-data'):
1469 1468
         if not isinstance(data, bytes):
1470  
-            content_type, data = _encode_multipart(data, content_type)
  1469
+            content_type, data = _encode_multipart(data.items(), content_type)
1471 1470
     elif content_type.startswith('application/x-www-form-urlencoded'):
1472 1471
         if has_files:
1473 1472
             raise ValueError('Submiting files is not allowed for'
14  webob/response.py
@@ -1277,8 +1277,18 @@ def gzip_app_iter(app_iter):
1277 1277
     for item in app_iter:
1278 1278
         size += len(item)
1279 1279
         crc = zlib.crc32(item, crc) & 0xffffffff
1280  
-        yield compress.compress(item)
1281  
-    yield compress.flush()
  1280
+
  1281
+        # The compress function may return zero length bytes if the input is
  1282
+        # small enough; it buffers the input for the next iteration or for a
  1283
+        # flush.
  1284
+        result = compress.compress(item)
  1285
+        if result:
  1286
+            yield result
  1287
+
  1288
+    # Similarly, flush may also not yield a value.
  1289
+    result = compress.flush()
  1290
+    if result:
  1291
+        yield result
1282 1292
     yield struct.pack("<2L", crc, size & 0xffffffff)
1283 1293
 
1284 1294
 def _error_unicode_in_app_iter(app_iter, body):
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.