0001-csvdatasource-keep-inline-newlines-when-parsing-CSV-.patch
passerelle/apps/csvdatasource/models.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import io |
|
17 | 18 |
import os |
18 | 19 |
import re |
19 | 20 |
import csv |
... | ... | |
222 | 223 |
file_type = self.csv_file.name.split('.')[-1] |
223 | 224 |
if file_type not in ('ods', 'xls', 'xlsx'): |
224 | 225 |
content = self.get_content_without_bom() |
225 |
reader = csv.reader(content.splitlines(), **self.dialect_options) |
|
226 |
if six.PY2: |
|
227 |
fd = io.BytesIO(content) |
|
228 |
else: |
|
229 |
fd = io.StringIO(content) |
|
230 |
reader = csv.reader(fd, **self.dialect_options) |
|
226 | 231 |
rows = list(reader) |
227 | 232 | |
228 | 233 |
else: |
tests/test_csv_datasource.py | ||
---|---|---|
16 | 16 |
# You should have received a copy of the GNU Affero General Public License |
17 | 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | |
19 |
import io |
|
19 | 20 |
import os |
20 | 21 |
import time |
21 | 22 |
import pytest |
... | ... | |
855 | 856 |
app = login(app) |
856 | 857 |
response = app.get(csvdata.get_absolute_url()) |
857 | 858 |
assert 'Oct. 27, 2019, 2:20 a.m.' in response |
859 | ||
860 | ||
861 |
def test_csv_multiline(app, setup, admin_user): |
|
862 |
csvdata, url = setup( |
|
863 |
'id,text,comment', |
|
864 |
filename='test.csv', |
|
865 |
data=io.BytesIO(b'''1,slug1,"un |
|
866 |
retour |
|
867 |
chariot" |
|
868 |
2,slug2,ok |
|
869 |
3,slug3,ok |
|
870 |
4,slug4,ok |
|
871 |
5,slug5,ok''')) |
|
872 | ||
873 |
response = app.get(url) |
|
874 |
assert response.json['data'][0] == { |
|
875 |
'comment': u'un\nretour\nchariot', |
|
876 |
'id': '1', |
|
877 |
'text': 'slug1', |
|
878 |
} |
|
858 |
- |