diff --git a/home/tests/import-export-data/trigger_deserialise_list_error.csv b/home/tests/import-export-data/trigger_deserialise_list_error.csv new file mode 100644 index 00000000..c4099f66 --- /dev/null +++ b/home/tests/import-export-data/trigger_deserialise_list_error.csv @@ -0,0 +1,4 @@ +title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,skip_threshold,skip_high_result_page,generic_error,question,explainer,error,min,max,answers,scores,answer_semantic_ids,question_semantic_id,answer_responses +Test assessment pt,categorical_question,"pt,test",test-assessment-pt,,pt,,,,,,0,,Generic error,Q1,,,,,A1,"one, ""two, three'",a1,q1,"""""" +Breastfeeding Quiz,categorical_question,"mnch,breastfeeding_quiz",breastfeeding-quiz,1,en,breastfeeding-quiz-champion,75,breastfeeding-quiz-good,25,breastfeeding-quiz-learner,100,,"Sorry, I didn't understand that. Please click one of the buttons.",*Question 1*,,,,,"Formula,Formula+breast milk,Breast milk only","one,two\nthree'","formula,formula-and-breast milk,breast-milk-only",baby-food@," +" \ No newline at end of file diff --git a/home/tests/test_assessment_import_export.py b/home/tests/test_assessment_import_export.py index 6fac2c77..4abb9fb5 100644 --- a/home/tests/test_assessment_import_export.py +++ b/home/tests/test_assessment_import_export.py @@ -668,6 +668,19 @@ def test_invalid_score_field(self, csv_impexp: ImportExport) -> None: ) assert e.value.row_num == 3 + def test_trigger_deserialise_list_error(self, csv_impexp: ImportExport) -> None: + """ + Importing a CSV with invalid data that fails the deserialise_list fucntion + should return a valid error message + """ + with pytest.raises(ImportAssessmentException) as e: + csv_impexp.import_file("trigger_deserialise_list_error.csv") + assert ( + e.value.message == "Invalid number format for score field. " + "The score value allows only a list of numbers separated by commas." + ) + assert e.value.row_num == 2 + def test_multiple_missing_headers(self, csv_impexp: ImportExport) -> None: """ Importing a CSV with multiple missing headers should return an error