Skip to content

Commit ba5fcf6

Browse files
committed
test #39, stringio has been read() can be read() again by seeking at 0
1 parent daecd7c commit ba5fcf6

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Change log
77
Added
88
********************************************************************************
99

10-
#. `issue 38 <https://github.com/pyexcel/django-excel/issues/38>`_, Support
11-
unicode code as download file name
10+
#. `issue 39 <https://github.com/pyexcel/django-excel/issues/39>`_, explicitly
11+
seeking at 0
1212

1313
0.0.7 - 29.06.2017
1414
--------------------------------------------------------------------------------

testResponse.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import pyexcel.ext.xlsx # noqa
1313
import pyexcel.ext.ods3 # noqa
1414
from django_excel._compact import urllib_quote
15+
from django_excel import ExcelInMemoryUploadedFile
1516
from nose.tools import eq_
1617

1718
PY2 = sys.version_info[0] == 2
@@ -20,6 +21,12 @@
2021
else:
2122
from collections import OrderedDict
2223

24+
if PY2:
25+
from StringIO import StringIO
26+
else:
27+
from io import StringIO
28+
29+
2330
_XLSX_MIME = (
2431
"application/" +
2532
"vnd.openxmlformats-officedocument.spreadsheetml.sheet")
@@ -279,3 +286,20 @@ class ExcelResponseUsingFileTestCase(ExcelResponseTestCase):
279286
@override_settings(FILE_UPLOAD_MAX_MEMORY_SIZE=1)
280287
class DatabaseOperationsUsingFileTestCase(DatabaseOperationsTestCase):
281288
pass
289+
290+
291+
class TestUploadedFile(TestCase):
292+
def test_in_memory_file(self):
293+
test_content = 'a,b,c'
294+
strio = StringIO(test_content)
295+
strio.read()
296+
in_memory_file = ExcelInMemoryUploadedFile(
297+
file=strio,
298+
field_name='test',
299+
name='test_file',
300+
content_type='text',
301+
size=3,
302+
charset=None
303+
)
304+
params = in_memory_file.get_params()
305+
eq_(params['file_content'], test_content)

0 commit comments

Comments
 (0)