Skip to content

Commit

Permalink
Merge pull request #1906 from josenavas/fix-dumps
Browse files Browse the repository at this point in the history
Make sure that the error message encoded is in utf8
  • Loading branch information
antgonza committed Jul 21, 2016
2 parents 6589d80 + a3d9db2 commit 4b632dd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion qiita_ware/dispatchable.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def create_sample_template(fp, study, is_mapping_file, data_type=None):
status = 'danger'
msg = str(e)

return {'status': status, 'message': msg}
return {'status': status, 'message': msg.decode('utf-8', 'replace')}


def update_sample_template(study_id, fp):
Expand Down
2 changes: 2 additions & 0 deletions qiita_ware/test/test_data/sample_info_utf8_error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Sample_name RUN_PREFIX TITLE nucleic_acid sample_type geo_loc_name COLLECTION_TIME description dna_extracted host_subject_id latitude longitude physical_specimen_remaining �collection_timestamp physical_specimen_location scientific_name taxon_id
sample1 341F-785R-Mineview-1-H4-A689_joined-SR dna bathing water Finland:Narpio 15.6.2015 mid june dna TRUE Not applicable Not applicable Not applicable TRUE Not applicable Not applicable Not applicable Not applicable
11 changes: 10 additions & 1 deletion qiita_ware/test/test_dispatchable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from unittest import TestCase, main
from tempfile import mkstemp
from os import close, remove
from os.path import exists
from os.path import exists, join, dirname, abspath

from qiita_core.util import qiita_test_checker
from qiita_ware.dispatchable import (
Expand Down Expand Up @@ -74,6 +74,15 @@ def test_create_sample_template(self):
"(id: 1) already exists."}
self.assertEqual(obs, exp)

def test_create_sample_template_nonutf8(self):
fp = join(dirname(abspath(__file__)), 'test_data',
'sample_info_utf8_error.txt')
obs = create_sample_template(fp, Study(1), False)
exp = {'status': 'danger',
'message': u"Non UTF-8 characters found in columns:"
u"\n\ufffdcollection_timestamp: row(s) 1"}
self.assertEqual(obs, exp)

def test_update_sample_template(self):
obs = update_sample_template(1, self.fp)
exp = {'status': 'warning',
Expand Down

0 comments on commit 4b632dd

Please sign in to comment.