summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8e971a1)
raw | patch | inline | side by side (parent: 8e971a1)
author | schlatterbeck <schlatterbeck@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 15 Jul 2011 12:36:47 +0000 (12:36 +0000) | ||
committer | schlatterbeck <schlatterbeck@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 15 Jul 2011 12:36:47 +0000 (12:36 +0000) |
returns unicode strings and expects a unicode string in the
constructor. Unfortunately csv doesn't handle unicode (yet). So we
need to use a BytesIO which gets the utf-8 string from the
web-interface. Compatibility for old versions by using
Stringio.Stringio for emulating a io.BytesIO also works.
- We didn't have a regression test for the EditCSVAction
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4633 57a73879-2fb5-44c3-a270-3262357dd7e2
constructor. Unfortunately csv doesn't handle unicode (yet). So we
need to use a BytesIO which gets the utf-8 string from the
web-interface. Compatibility for old versions by using
Stringio.Stringio for emulating a io.BytesIO also works.
- We didn't have a regression test for the EditCSVAction
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4633 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/anypy/io_.py | patch | blob | history | |
roundup/cgi/actions.py | patch | blob | history | |
test/test_cgi.py | patch | blob | history |
diff --git a/roundup/anypy/io_.py b/roundup/anypy/io_.py
index 86f8023d83da471c02f5d9684f27c298b8aeda2b..5d6e52e2512031fe456286c25250146c292572cc 100644 (file)
--- a/roundup/anypy/io_.py
+++ b/roundup/anypy/io_.py
try:
- from io import StringIO
+ from io import StringIO, BytesIO
except:
from StringIO import StringIO
+ BytesIO = StringIO
diff --git a/roundup/cgi/actions.py b/roundup/cgi/actions.py
index d48fb595eb75514bd47c74a4bd8abbbfefec8466..86bd4f1f112a5e2e82eb936ad6d0a185da6033bd 100755 (executable)
--- a/roundup/cgi/actions.py
+++ b/roundup/cgi/actions.py
props = ['id'] + props_without_id
# do the edit
- rows = io_.StringIO(self.form['rows'].value)
+ rows = io_.BytesIO(self.form['rows'].value)
reader = csv.reader(rows)
found = {}
line = 0
diff --git a/test/test_cgi.py b/test/test_cgi.py
index 7fbe89ce442440091c434b23a51bff5a84ffe755..c99d9e8cfa51f386e8cd403a7a9e8f8bcf8a3141 100644 (file)
--- a/test/test_cgi.py
+++ b/test/test_cgi.py
h = HTMLRequest(cl)
self.assertEqual([x.id for x in h.batch()],['1', '2', '3'])
+ def testEditCSV(self):
+ form = dict(rows='id,name\n1,newkey')
+ cl = self._make_client(form, userid='1', classname='keyword')
+ cl.ok_message = []
+ actions.EditCSVAction(cl).handle()
+ self.assertEqual(cl.ok_message, ['Items edited OK'])
+ k = self.db.keyword.getnode('1')
+ self.assertEqual(k.name, 'newkey')
+ form = dict(rows=u'id,name\n1,\xe4\xf6\xfc'.encode('utf-8'))
+ cl = self._make_client(form, userid='1', classname='keyword')
+ cl.ok_message = []
+ actions.EditCSVAction(cl).handle()
+ self.assertEqual(cl.ok_message, ['Items edited OK'])
+ k = self.db.keyword.getnode('1')
+ self.assertEqual(k.name, u'\xe4\xf6\xfc'.encode('utf-8'))
+
def testRoles(self):
cl = self._make_client({})
self.db.user.set('1', roles='aDmin, uSer')