Skip to content

Commit eafad6c

Browse files
committed
fix #4: passing on extra keywords
1 parent 8969f7e commit eafad6c

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

pyexcel_webio/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ def get_params(self, field_name=None, **keywords):
204204
if file_type is not None and file_handle is not None:
205205
content = file_handle.read()
206206
if content:
207-
keywords = {
207+
params = {
208208
'file_type': file_type,
209209
'file_content': content
210210
}
211+
keywords.update(params)
211212
return keywords
212213
else:
213214
raise IOError("No content was uploaded")

tests/common.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pyexcel_webio as webio
2+
3+
4+
class TestInput(webio.ExcelInput):
5+
"""This is sample implementation that read excel source from file"""
6+
def get_params(self, **keywords):
7+
"""Load a single sheet"""
8+
return keywords
9+
10+
11+
class TestExtendedInput(webio.ExcelInputInMultiDict):
12+
"""This is sample implementation that read excel source from file"""
13+
def get_file_tuple(self, field_name):
14+
return field_name

tests/fixtures/issue4-broken.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Last Name,First Name,Company,Email,Job TitleTest,Th�s,Cool Co,test.this@example.com,Founder

tests/test_bug_fixes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
import os
3+
from common import TestExtendedInput
4+
from nose.tools import eq_
5+
6+
7+
def test_issue_4():
8+
myinput = TestExtendedInput()
9+
fixture = os.path.join("tests", "fixtures", "issue4-broken.csv")
10+
with open(fixture, "r") as f:
11+
array = myinput.get_array(field_name=('csv', f), encoding='latin1')
12+
expected = [
13+
[u'Last Name', u'First Name', u'Company', u'Email', u'Job Title'],
14+
[u'Test', u'Th\xefs', u'Cool Co',
15+
u'test.this@example.com', u'Founder']
16+
]
17+
eq_(array, expected)

tests/test_webio.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest import TestCase
44
import pyexcel as pe
55
import pyexcel_webio as webio
6+
from common import TestInput, TestExtendedInput
67
from db import Session, Base, Signature, Signature2, engine
78
from nose.tools import raises, eq_
89
if sys.version_info[0] == 2 and sys.version_info[1] < 7:
@@ -14,19 +15,6 @@
1415
OUTPUT = "%s.xls" % FILE_NAME
1516

1617

17-
class TestInput(webio.ExcelInput):
18-
"""This is sample implementation that read excel source from file"""
19-
def get_params(self, **keywords):
20-
"""Load a single sheet"""
21-
return keywords
22-
23-
24-
class TestExtendedInput(webio.ExcelInputInMultiDict):
25-
"""This is sample implementation that read excel source from file"""
26-
def get_file_tuple(self, field_name):
27-
return field_name
28-
29-
3018
def dumpy_response(content, content_type=None, status=200, file_name=None):
3119
"""A dummy response"""
3220
with open(file_name, 'wb') as f:
@@ -52,32 +40,32 @@ def test_excel_input_get_file_tuple(self):
5240
testinput = webio.ExcelInputInMultiDict()
5341
testinput.get_file_tuple(field_name="test") # booom
5442

55-
@raises(NotImplementedError)
43+
@raises(pe.sources.factory.UnknownParameters)
5644
def test_get_sheet(self):
5745
myinput = TestInput()
5846
myinput.get_sheet(unrelated="foo bar")
5947

60-
@raises(NotImplementedError)
48+
@raises(pe.sources.factory.UnknownParameters)
6149
def test_get_array(self):
6250
myinput = TestInput()
6351
myinput.get_array(unrelated="foo bar")
6452

65-
@raises(NotImplementedError)
53+
@raises(pe.sources.factory.UnknownParameters)
6654
def test_get_dict(self):
6755
myinput = TestInput()
6856
myinput.get_dict(unrelated="foo bar")
6957

70-
@raises(NotImplementedError)
58+
@raises(pe.sources.factory.UnknownParameters)
7159
def test_get_records(self):
7260
myinput = TestInput()
7361
myinput.get_records(unrelated="foo bar")
7462

75-
@raises(NotImplementedError)
63+
@raises(pe.sources.factory.UnknownParameters)
7664
def test_get_book(self):
7765
myinput = TestInput()
7866
myinput.get_book(unrelated="foo bar")
7967

80-
@raises(NotImplementedError)
68+
@raises(pe.sources.factory.UnknownParameters)
8169
def test_get_book_dict(self):
8270
myinput = TestInput()
8371
myinput.get_book_dict(unrelated="foo bar")

0 commit comments

Comments
 (0)