changeset 1156:4cd6611b0cf8

Fix send_file(None) and send_file unittest
author Sam Toyer <samATqxcvDOTnet>
date Wed, 14 Dec 2011 10:29:18 +1000
parents 0807f3505c13
children f5f70c50cc51
files MoinMoin/util/_tests/test_send_file.py MoinMoin/util/send_file.py
diffstat 2 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/util/_tests/test_send_file.py	Wed Dec 14 00:45:49 2011 +0100
+++ b/MoinMoin/util/_tests/test_send_file.py	Wed Dec 14 10:29:18 2011 +1000
@@ -30,7 +30,7 @@
     def test_temptest(self):
         self.makefile(self.fname, 'test_content')
         result = send_file.send_file(self.fname, as_attachment = True, conditional = True)
-        expected = '<Response 12 bytes [200 OK]>'
+        expected = '<Response streamed [200 OK]>'
         assert str(result) == expected
 
         with pytest.raises(TypeError):
--- a/MoinMoin/util/send_file.py	Wed Dec 14 00:45:49 2011 +0100
+++ b/MoinMoin/util/send_file.py	Wed Dec 14 10:29:18 2011 +1000
@@ -119,11 +119,13 @@
     # See `_ensure_sequence` in werkzeug/wrappers.py
     if filename:
         fsize = os.path.getsize(filename)
-    else:
+    elif file:
         # Seek 0 bytes (0) from the end of the file (2)
         file.seek(0, 2)
         fsize = file.tell()
         file.seek(0, 0)
+    else:
+        fsize = 0
     headers.add('Content-Length', fsize)
 
     if as_attachment: