diff --git a/qiita_ware/dispatchable.py b/qiita_ware/dispatchable.py index 3780415ae..5a5d21484 100644 --- a/qiita_ware/dispatchable.py +++ b/qiita_ware/dispatchable.py @@ -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): diff --git a/qiita_ware/test/test_data/sample_info_utf8_error.txt b/qiita_ware/test/test_data/sample_info_utf8_error.txt new file mode 100644 index 000000000..0c0f03553 --- /dev/null +++ b/qiita_ware/test/test_data/sample_info_utf8_error.txt @@ -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 diff --git a/qiita_ware/test/test_dispatchable.py b/qiita_ware/test/test_dispatchable.py index e35ff5a2a..ead09f2f3 100644 --- a/qiita_ware/test/test_dispatchable.py +++ b/qiita_ware/test/test_dispatchable.py @@ -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 ( @@ -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',