Skip to content

Commit

Permalink
csv: delimiter passing
Browse files Browse the repository at this point in the history
* FIX Properly passes CSV delimiter to the previewer template.

Signed-off-by: Alexander Ioannidis <a.ioannidis@cern.ch>
  • Loading branch information
slint authored and jirikuncar committed Sep 22, 2016
1 parent a0e5229 commit 3ef14a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion invenio_previewer/extensions/csv_dthreejs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def validate_csv(file):
try:
# Detect encoding and dialect
encoding = chardet.detect(sample).get('encoding')
delimiter = csv.Sniffer().sniff(sample.decode(encoding))
delimiter = csv.Sniffer().sniff(sample.decode(encoding)).delimiter
is_valid = True
except Exception as e:
current_app.logger.debug(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ def test_csv_dthreejs_extension(app, webassets, bucket, record):
with app.test_client() as client:
res = client.get(preview_url(record['control_number'], 'test.csv'))
assert 'data-csv-source="' in res.get_data(as_text=True)
assert 'data-csv-delimiter=","' in res.get_data(as_text=True)


def test_csv_dthreejs_delimiter(app, webassets, bucket, record):
"""Test view with csv files."""
create_file(record, bucket, 'test.csv', BytesIO(b'A#B\n1#2'))
with app.test_client() as client:
res = client.get(preview_url(record['control_number'], 'test.csv'))
assert 'data-csv-source="' in res.get_data(as_text=True)
assert 'data-csv-delimiter="#"' in res.get_data(as_text=True)


def test_zip_extension(app, webassets, bucket, record, zip_fp):
Expand Down

0 comments on commit 3ef14a3

Please sign in to comment.