From 067b2342f4ddab48b53555c586a49189130768f9 Mon Sep 17 00:00:00 2001 From: devchima Date: Thu, 20 Jun 2024 03:34:29 -0400 Subject: [PATCH] Add integer type question with min and max fields --- CHANGELOG.md | 1 + home/export_assessments.py | 6 + home/import_assessments.py | 8 + .../0070_alter_assessment_questions.py | 220 ++++++++++++++++++ home/models.py | 13 ++ home/serializers.py | 4 + .../assessment_less_simple.csv | 9 +- .../assessment_missing_related_page.csv | 8 +- .../import-export-data/assessment_simple.csv | 8 +- .../import-export-data/bulk_assessments.csv | 49 ++-- .../comma_separated_answers.csv | 4 +- .../multiple_assessments.csv | 17 +- home/tests/test_api.py | 35 +++ home/tests/test_serializers.py | 6 +- 14 files changed, 340 insertions(+), 48 deletions(-) create mode 100644 home/migrations/0070_alter_assessment_questions.py diff --git a/CHANGELOG.md b/CHANGELOG.md index ac4381e0..967a631b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add Semantic ID for form answers - Add version number to distinguish question sets - Add Freetext question type for forms +- Add Integer question with min and max values ### Changed - Increased SMS limit to 459 characters diff --git a/home/export_assessments.py b/home/export_assessments.py index 532f9daf..aa1495c8 100644 --- a/home/export_assessments.py +++ b/home/export_assessments.py @@ -34,6 +34,8 @@ class ExportRow: question: str explainer: str error: str + min: int + max: int answers: str scores: str semantic_ids: str @@ -85,6 +87,8 @@ def perform_export(self) -> Iterable[ExportRow]: question=question.value["question"], explainer=question.value["explainer"], error=question.value.get("error"), + min=question.value.get("min"), + max=question.value.get("max"), answers=serialize_list(answers), scores=serialize_list(scores), semantic_ids=serialize_list(semantic_ids), @@ -161,6 +165,8 @@ def _set_xlsx_styles(wb: Workbook, sheet: Worksheet) -> None: "question": 370, "explainer": 370, "error": 370, + "min": 110, + "max": 110, "answers": 370, "scores": 110, "semantic_ids": 110, diff --git a/home/import_assessments.py b/home/import_assessments.py index 1329ab06..7c7b61db 100644 --- a/home/import_assessments.py +++ b/home/import_assessments.py @@ -171,6 +171,8 @@ def create_shadow_assessment_from_row( question = ShadowQuestionBlock( question=row.question, error=row.error, + min=row.min, + max=row.max, answers=answers, type=row.question_type, explainer=row.explainer, @@ -194,6 +196,8 @@ class ShadowQuestionBlock: answers: list[ShadowAnswerBlock] explainer: str = "" error: str = "" + min: str = "" + max: str = "" type: str = "" @@ -275,6 +279,8 @@ def questions_as_streamfield(self) -> list[dict[str, Any]]: "answers": answers, "explainer": question.explainer, "error": question.error, + "min": question.min, + "max": question.max, }, } ) @@ -302,6 +308,8 @@ class AssessmentRow: question: str = "" explainer: str = "" error: str = "" + min: str = "" + max: str = "" answers: list[str] = field(default_factory=list) scores: list[float] = field(default_factory=list) semantic_ids: list[str] = field(default_factory=list) diff --git a/home/migrations/0070_alter_assessment_questions.py b/home/migrations/0070_alter_assessment_questions.py new file mode 100644 index 00000000..3d812352 --- /dev/null +++ b/home/migrations/0070_alter_assessment_questions.py @@ -0,0 +1,220 @@ +# Generated by Django 4.2.11 on 2024-06-20 06:39 + +from django.db import migrations +import wagtail.blocks +import wagtail.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ("home", "0069_alter_assessment_questions"), + ] + + operations = [ + migrations.AlterField( + model_name="assessment", + name="questions", + field=wagtail.fields.StreamField( + [ + ( + "categorical_question", + wagtail.blocks.StructBlock( + [ + ( + "question", + wagtail.blocks.TextBlock( + help_text="The question to ask the user" + ), + ), + ( + "explainer", + wagtail.blocks.TextBlock( + help_text="Explainer message which tells the user why we need this question", + required=False, + ), + ), + ( + "error", + wagtail.blocks.TextBlock( + help_text="Error message for this question if we don't understand the input", + required=False, + ), + ), + ( + "answers", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "answer", + wagtail.blocks.TextBlock( + help_text="The choice shown to the user for this option" + ), + ), + ( + "score", + wagtail.blocks.FloatBlock( + help_text="How much to add to the total score if this answer is chosen" + ), + ), + ( + "semantic_id", + wagtail.blocks.TextBlock( + help_text="Semantic ID for this answer" + ), + ), + ] + ) + ), + ), + ] + ), + ), + ( + "age_question", + wagtail.blocks.StructBlock( + [ + ( + "question", + wagtail.blocks.TextBlock( + help_text="The question to ask the user" + ), + ), + ( + "explainer", + wagtail.blocks.TextBlock( + help_text="Explainer message which tells the user why we need this question", + required=False, + ), + ), + ( + "error", + wagtail.blocks.TextBlock( + help_text="Error message for this question if we don't understand the input", + required=False, + ), + ), + ] + ), + ), + ( + "multiselect_question", + wagtail.blocks.StructBlock( + [ + ( + "question", + wagtail.blocks.TextBlock( + help_text="The question to ask the user" + ), + ), + ( + "explainer", + wagtail.blocks.TextBlock( + help_text="Explainer message which tells the user why we need this question", + required=False, + ), + ), + ( + "error", + wagtail.blocks.TextBlock( + help_text="Error message for this question if we don't understand the input", + required=False, + ), + ), + ( + "answers", + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( + [ + ( + "answer", + wagtail.blocks.TextBlock( + help_text="The choice shown to the user for this option" + ), + ), + ( + "score", + wagtail.blocks.FloatBlock( + help_text="How much to add to the total score if this answer is chosen" + ), + ), + ( + "semantic_id", + wagtail.blocks.TextBlock( + help_text="Semantic ID for this answer" + ), + ), + ] + ) + ), + ), + ] + ), + ), + ( + "freetext_question", + wagtail.blocks.StructBlock( + [ + ( + "question", + wagtail.blocks.TextBlock( + help_text="The question to ask the user" + ), + ), + ( + "explainer", + wagtail.blocks.TextBlock( + help_text="Explainer message which tells the user why we need this question", + required=False, + ), + ), + ] + ), + ), + ( + "integer_question", + wagtail.blocks.StructBlock( + [ + ( + "question", + wagtail.blocks.TextBlock( + help_text="The question to ask the user" + ), + ), + ( + "explainer", + wagtail.blocks.TextBlock( + help_text="Explainer message which tells the user why we need this question", + required=False, + ), + ), + ( + "error", + wagtail.blocks.TextBlock( + help_text="Error message for this question if we don't understand the input", + required=False, + ), + ), + ( + "min", + wagtail.blocks.IntegerBlock( + help_text="The minimum value that can be entered", + required=False, + ), + ), + ( + "max", + wagtail.blocks.IntegerBlock( + help_text="The maximum value that can be entered", + required=False, + ), + ), + ] + ), + ), + ], + use_json_field=True, + ), + ), + ] diff --git a/home/models.py b/home/models.py index 3c4b3b33..238abe1c 100644 --- a/home/models.py +++ b/home/models.py @@ -1338,6 +1338,18 @@ class FreeTextQuestionBlock(BaseQuestionBlock): error = None +class IntegerQuestionBlock(BaseQuestionBlock): + min = blocks.IntegerBlock( + required=False, + help_text="The minimum value that can be entered", + ) + max = blocks.IntegerBlock( + required=False, + help_text="The maximum value that can be entered", + ) + answers = None + + class AssessmentTag(TaggedItemBase): content_object = ParentalKey( "Assessment", on_delete=models.CASCADE, related_name="tagged_items" @@ -1396,6 +1408,7 @@ class Assessment(DraftStateMixin, RevisionMixin, index.Indexed, ClusterableModel ("age_question", AgeQuestionBlock()), ("multiselect_question", MultiselectQuestionBlock()), ("freetext_question", FreeTextQuestionBlock()), + ("integer_question", IntegerQuestionBlock()), ], use_json_field=True, ) diff --git a/home/serializers.py b/home/serializers.py index e7fd9f3d..75ec569f 100644 --- a/home/serializers.py +++ b/home/serializers.py @@ -543,6 +543,8 @@ class QuestionField(serializers.Field): "question": "How much wood would a woodchuck chuck if a woodchuck could chuck wood?", "explainer": None, "error": "Unknown answer given", + "min": 100, + "max": 500, "answers": [ { "answer": "Yes", @@ -567,6 +569,8 @@ def to_representation(self, page): "question": question["value"]["question"], "explainer": question.get("value", {}).get("explainer"), "error": question.get("value", {}).get("error"), + "min": question.get("value", {}).get("min"), + "max": question.get("value", {}).get("max"), "answers": [ x["value"] for x in question["value"].get("answers", []) ], diff --git a/home/tests/import-export-data/assessment_less_simple.csv b/home/tests/import-export-data/assessment_less_simple.csv index dbc5a360..c307b5ff 100644 --- a/home/tests/import-export-data/assessment_less_simple.csv +++ b/home/tests/import-export-data/assessment_less_simple.csv @@ -1,4 +1,5 @@ -title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,answers,scores,semantic_ids -Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't understand.,"Once a week,Twice a week,Thrice a week","1.0,3.0,4.5","test-1,test-2,test-3" -Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",Have you been vaccinated against COVID-19?,We need to know if you have been vaccinated for a proper risk assessment,Sorry we didn't quite catch that.,"Yes,No","3.0,1.0","test-1,test-2" -Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How high is your temperature?,We need to know your temperature for a proper risk assessment. A very high temperature could suggest an infection is present.,Please choose the option that matches your answer.,"Between 37.5C and 38C,Between 38.1C and 40C,Between 40.1C and 41.1C","3.0,2.0,1.0","test-1,test-2,test-3" +title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,min,max,answers,scores,semantic_ids +Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't understand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.0,4.5","test-1,test-2,test-3" +Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",Have you been vaccinated against COVID-19?,We need to know if you have been vaccinated for a proper risk assessment,Sorry we didn't quite catch that.,,,"Yes,No","3.0,1.0","test-1,test-2" +Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How high is your temperature?,We need to know your temperature for a proper risk assessment. A very high temperature could suggest an infection is present.,Please choose the option that matches your answer.,,,"Between 37.5C and 38C,Between 38.1C and 40C,Between 40.1C and 41.1C","3.0,2.0,1.0","test-1,test-2,test-3" +Integer Type Question,integer_question,integer-type-question,integer-type-question,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,How much do you weigh in kilograms?,We need to test integer type questions,Sorry your min and max weight should be between 40 and 500kg.,40,500,,, diff --git a/home/tests/import-export-data/assessment_missing_related_page.csv b/home/tests/import-export-data/assessment_missing_related_page.csv index c1162212..29ce2b27 100644 --- a/home/tests/import-export-data/assessment_missing_related_page.csv +++ b/home/tests/import-export-data/assessment_missing_related_page.csv @@ -1,4 +1,4 @@ -title,question_type,tags,slug,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,questions,error,answers,score,semantic_ids -Fake Test,categorical_question,"Random, selection",fake-test,en,fake-page,4,fake-page,3,fake-page,We did not quite get that,Select a number for the first question,Please retry,"A,B","4.0,1.0","test-1,test-2" -Fake Test,categorical_question,"Random, selection",fake-test,en,fake-page,4,fake-page,3,fake-page,We did not quite get that,Select a number for the second question,We did not quite get that,"A,B,C","1.0,3.0,4.0","test-1,test-2,test-3" -Fake Test,categorical_question,"Random, selection",fake-test,en,fake-page,4,fake-page,3,fake-page,We did not quite get that,Select a number for the third question,Sorry we did not quite get that,"A,B,C","2.0,1.0,2.0","test-1,test-2,test-3" +title,question_type,tags,slug,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,questions,error,min,max,answers,score,semantic_ids +Fake Test,categorical_question,"Random, selection",fake-test,en,fake-page,4,fake-page,3,fake-page,We did not quite get that,Select a number for the first question,Please retry,,,"A,B","4.0,1.0","test-1,test-2" +Fake Test,categorical_question,"Random, selection",fake-test,en,fake-page,4,fake-page,3,fake-page,We did not quite get that,Select a number for the second question,We did not quite get that,,,"A,B,C","1.0,3.0,4.0","test-1,test-2,test-3" +Fake Test,categorical_question,"Random, selection",fake-test,en,fake-page,4,fake-page,3,fake-page,We did not quite get that,Select a number for the third question,Sorry we did not quite get that,,,"A,B,C","2.0,1.0,2.0","test-1,test-2,test-3" diff --git a/home/tests/import-export-data/assessment_simple.csv b/home/tests/import-export-data/assessment_simple.csv index e38e20c6..5fcbe3d3 100644 --- a/home/tests/import-export-data/assessment_simple.csv +++ b/home/tests/import-export-data/assessment_simple.csv @@ -1,4 +1,4 @@ -title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,answers,scores,semantic_ids -Health Assessment Simple,categorical_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,"Once a week,Twice a week,Thrice a week","1.0,3.5,4.5","test-1,test-2,test-3" -Health Assessment Simple,age_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,,, -Health Assessment Simple,multiselect_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,"Once a week,Twice a week,Thrice a week","1.0,3.5,4.5","test-1,test-2,test-3" +title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,min,max,answers,scores,semantic_ids +Health Assessment Simple,categorical_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.5,4.5","test-1,test-2,test-3" +Health Assessment Simple,age_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,,,,, +Health Assessment Simple,multiselect_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know your blood pressure for a proper risk assessment,Sorry we don't under stand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.5,4.5","test-1,test-2,test-3" diff --git a/home/tests/import-export-data/bulk_assessments.csv b/home/tests/import-export-data/bulk_assessments.csv index a38f9608..a731994e 100644 --- a/home/tests/import-export-data/bulk_assessments.csv +++ b/home/tests/import-export-data/bulk_assessments.csv @@ -1,24 +1,25 @@ -title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,answers,scores,semantic_ids -Health Assessment Simple,categorical_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know this for a proper risk assessment,Sorry we don't under stand.,"Once a week,Twice a week,Thrice a week","1.0,3.5,4.5","test-1,test-2,test-3" -Geography Trivia 2,categorical_question,"trivia,geography",Geography-trivia-2,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,What country is known as 'The Emerald Isle'?,We need to know this for a proper risk assessment,Sorry we didn't get that,"Maldives,Ireland,Philippines","0.0,2.0,0.0","test-1,test-2,test-3" -Geography Trivia 2,categorical_question,"trivia,geography",Geography-trivia-2,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,What country has the longest coastline?,We need to know this for a proper risk assessment,Sorry we didn't get that,"Russia,Indonesia,Canada","0.0,0.0,2.0","test-1,test-2,test-3" -Geography Trivia 2,categorical_question,"trivia,geography",Geography-trivia-2,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,Which of these countries is NOT in Asia?,We need to know this for a proper risk assessment,Sorry we didn't get that,"Bosnia,Israel,Thailand","2.0,0.0,0.0","test-1,test-2,test-3" -Engineering Trivia,categorical_question,engineering,engineering-trivia,v1.0,en,high-inflection,6.0,medium-score,4.0,low-score,Just a generic error,Who invented the light bulb?,We need to know this for a proper risk assessment,We didn't quite get that,"Thomas Edison,Nikola Tesla,Albert Einstein","2.0,2.0,0.0","test-1,test-2,test-3" -Engineering Trivia,categorical_question,engineering,engineering-trivia,v1.0,en,high-inflection,6.0,medium-score,4.0,low-score,Just a generic error,Some planes can fly faster than the speed of light?,We need to know this for a proper risk assessment,We didn't quite get that,"True,False","0.0,2.0","test-1,test-2" -Engineering Trivia,categorical_question,engineering,engineering-trivia,v1.0,en,high-inflection,6.0,medium-score,4.0,low-score,Just a generic error,In what century was the mechanical clock invented?,We need to know this for a proper risk assessment,This is an error message,"13th century,16th century,18th century,14th century","0.0,0.0,0.0,2.0","test-1,test-2,test-3,test-4" -Geography Trivia,categorical_question,"trivia,geography",geography-trivia,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,What country is known as 'The Emerald Isle'?,We need to know this for a proper risk assessment,Sorry we didn't get that,"Maldives,Ireland,Philippines","0.0,2.0,0.0","test-1,test-2,test-3" -Geography Trivia,categorical_question,"trivia,geography",geography-trivia,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,What country has the longest coastline?,We need to know this for a proper risk assessment,Sorry we didn't get that,"Russia,Indonesia,Canada","0.0,0.0,2.0","test-1,test-2,test-3" -Geography Trivia,categorical_question,"trivia,geography",geography-trivia,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,Which of these countries is NOT in Asia?,We need to know this for a proper risk assessment,Sorry we didn't get that,"Bosnia,Israel,Thailand","2.0,0.0,0.0","test-1,test-2,test-3" -Medical Trivia,categorical_question,"medicine,trivia",medical-trivia,v1.0,en,high-inflection,4.5,medium-score,3.0,low-score,This is a generic error,How many square feet is the average adult human’s skin?,We need to know this for a proper risk assessment,Sorry we didn't get that,"19 feet,21 feet,15 feet","2.0,0.0,0.0","test-1,test-2,test-3" -Medical Trivia,categorical_question,"medicine,trivia",medical-trivia,v1.0,en,high-inflection,4.5,medium-score,3.0,low-score,This is a generic error,What type of blood cells fight infections and diseases?,We need to know this for a proper risk assessment,Sorry we didn't get that,"White blood cells,Red blood cells,Stem cells","2.0,0.0,0.0","test-1,test-2,test-3" -Medical Trivia,categorical_question,"medicine,trivia",medical-trivia,v1.0,en,high-inflection,4.5,medium-score,3.0,low-score,This is a generic error,What does cartilage link?,We need to know this for a proper risk assessment,Sorry we didn't get that,"Joints and bones,Digestive system","2.0,0.0","test-1,test-2" -Trivia Assessment,categorical_question,astrophysics,trivia-assessment,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,Aureolin is a shade of what color?,We need to know this for a proper risk assessment,Sorry we don't understand,"Pink,Yellow,Blue","0.0,1.0,0.0","test-1,test-2,test-3" -Trivia Assessment,categorical_question,astrophysics,trivia-assessment,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,How many ghosts chase Pac-Man at the start of each game?,We need to know this for a proper risk assessment,Sorry we didn't get that,"2,4.0,3","0.0,2.0,0.0","test-1,test-2,test-3" -Trivia Assessment,categorical_question,astrophysics,trivia-assessment,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,What Renaissance artist is buried in Rome's Pantheon?,We need to know this for a proper risk assessment,Sorry we didn't get that,"Raphael,Angelo,Rijkaard","2.0,0.0,0.0","test-1,test-2,test-3" -Trivia Assessment,categorical_question,astrophysics,trivia-assessment,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,What game studio makes the Red Dead Redemption series?,We need to know this for a proper risk assessment,Sorry we didn't get that,"Rockstar,Capcom,Konami","1.0,0.0,0.0","test-1,test-2,test-3" -Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the first question,We need to know this for a proper risk assessment,Please retry,"A,B","4.0,1.0","test-1,test-2" -Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the second question,We need to know this for a proper risk assessment,We did not quite get that,"A,B,C","1.0,3.0,4.0","test-1,test-2,test-3" -Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the third question,We need to know this for a proper risk assessment,Sorry we did not quite get that,"A,B,C","2.0,1.0,2.0","test-1,test-2,test-3" -Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know this for a proper risk assessment,Sorry we don't understand.,"Once a week,Twice a week,Thrice a week","1.0,3.0,4.5","test-1,test-2,test-3" -Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",Have you been vaccinated against COVID-19?,We need to know this for a proper risk assessment,Sorry we didn't quite catch that.,"Yes,No","3.0,1.0","test-1,test-2" -Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How high is your temperature?,We need to know this for a proper risk assessment,Please choose the option that matches your answer.,"Between 37.5C and 38C,Between 38.1C and 40C,Between 40.1C and 41.1C","3.0,2.0,1.0","test-1,test-2,test-3" +title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,min,max,answers,scores,semantic_ids +Health Assessment Simple,categorical_question,checker,Health-assessment-simple,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know this for a proper risk assessment,Sorry we don't under stand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.5,4.5","test-1,test-2,test-3" +Geography Trivia 2,categorical_question,"trivia,geography",Geography-trivia-2,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,What country is known as 'The Emerald Isle'?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"Maldives,Ireland,Philippines","0.0,2.0,0.0","test-1,test-2,test-3" +Geography Trivia 2,categorical_question,"trivia,geography",Geography-trivia-2,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,What country has the longest coastline?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"Russia,Indonesia,Canada","0.0,0.0,2.0","test-1,test-2,test-3" +Geography Trivia 2,categorical_question,"trivia,geography",Geography-trivia-2,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,Which of these countries is NOT in Asia?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"Bosnia,Israel,Thailand","2.0,0.0,0.0","test-1,test-2,test-3" +Engineering Trivia,categorical_question,engineering,engineering-trivia,v1.0,en,high-inflection,6.0,medium-score,4.0,low-score,Just a generic error,Who invented the light bulb?,We need to know this for a proper risk assessment,We didn't quite get that,,,"Thomas Edison,Nikola Tesla,Albert Einstein","2.0,2.0,0.0","test-1,test-2,test-3" +Engineering Trivia,categorical_question,engineering,engineering-trivia,v1.0,en,high-inflection,6.0,medium-score,4.0,low-score,Just a generic error,Some planes can fly faster than the speed of light?,We need to know this for a proper risk assessment,We didn't quite get that,,,"True,False","0.0,2.0","test-1,test-2" +Engineering Trivia,categorical_question,engineering,engineering-trivia,v1.0,en,high-inflection,6.0,medium-score,4.0,low-score,Just a generic error,In what century was the mechanical clock invented?,We need to know this for a proper risk assessment,This is an error message,,,"13th century,16th century,18th century,14th century","0.0,0.0,0.0,2.0","test-1,test-2,test-3,test-4" +Geography Trivia,categorical_question,"trivia,geography",geography-trivia,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,What country is known as 'The Emerald Isle'?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"Maldives,Ireland,Philippines","0.0,2.0,0.0","test-1,test-2,test-3" +Geography Trivia,categorical_question,"trivia,geography",geography-trivia,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,What country has the longest coastline?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"Russia,Indonesia,Canada","0.0,0.0,2.0","test-1,test-2,test-3" +Geography Trivia,categorical_question,"trivia,geography",geography-trivia,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,This is a generic error,Which of these countries is NOT in Asia?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"Bosnia,Israel,Thailand","2.0,0.0,0.0","test-1,test-2,test-3" +Medical Trivia,categorical_question,"medicine,trivia",medical-trivia,v1.0,en,high-inflection,4.5,medium-score,3.0,low-score,This is a generic error,How many square feet is the average adult human’s skin?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"19 feet,21 feet,15 feet","2.0,0.0,0.0","test-1,test-2,test-3" +Medical Trivia,categorical_question,"medicine,trivia",medical-trivia,v1.0,en,high-inflection,4.5,medium-score,3.0,low-score,This is a generic error,What type of blood cells fight infections and diseases?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"White blood cells,Red blood cells,Stem cells","2.0,0.0,0.0","test-1,test-2,test-3" +Medical Trivia,categorical_question,"medicine,trivia",medical-trivia,v1.0,en,high-inflection,4.5,medium-score,3.0,low-score,This is a generic error,What does cartilage link?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"Joints and bones,Digestive system","2.0,0.0","test-1,test-2" +Trivia Assessment,categorical_question,astrophysics,trivia-assessment,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,Aureolin is a shade of what color?,We need to know this for a proper risk assessment,Sorry we don't understand,,,"Pink,Yellow,Blue","0.0,1.0,0.0","test-1,test-2,test-3" +Trivia Assessment,categorical_question,astrophysics,trivia-assessment,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,How many ghosts chase Pac-Man at the start of each game?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"2,4.0,3","0.0,2.0,0.0","test-1,test-2,test-3" +Trivia Assessment,categorical_question,astrophysics,trivia-assessment,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,What Renaissance artist is buried in Rome's Pantheon?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"Raphael,Angelo,Rijkaard","2.0,0.0,0.0","test-1,test-2,test-3" +Trivia Assessment,categorical_question,astrophysics,trivia-assessment,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,What game studio makes the Red Dead Redemption series?,We need to know this for a proper risk assessment,Sorry we didn't get that,,,"Rockstar,Capcom,Konami","1.0,0.0,0.0","test-1,test-2,test-3" +Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the first question,We need to know this for a proper risk assessment,Please retry,,,"A,B","4.0,1.0","test-1,test-2" +Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the second question,We need to know this for a proper risk assessment,We did not quite get that,,,"A,B,C","1.0,3.0,4.0","test-1,test-2,test-3" +Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the third question,We need to know this for a proper risk assessment,Sorry we did not quite get that,,,"A,B,C","2.0,1.0,2.0","test-1,test-2,test-3" +Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know this for a proper risk assessment,Sorry we don't understand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.0,4.5","test-1,test-2,test-3" +Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",Have you been vaccinated against COVID-19?,We need to know this for a proper risk assessment,Sorry we didn't quite catch that.,,,"Yes,No","3.0,1.0","test-1,test-2" +Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How high is your temperature?,We need to know this for a proper risk assessment,Please choose the option that matches your answer.,,,"Between 37.5C and 38C,Between 38.1C and 40C,Between 40.1C and 41.1C","3.0,2.0,1.0","test-1,test-2,test-3" +Integer Type Question,integer_question,integer-type-question,integer-type-question,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,How much do you weigh in kilograms?,We need to test integer type questions,Sorry your min and max weight should be between 40 and 500kg.,40,500,,, diff --git a/home/tests/import-export-data/comma_separated_answers.csv b/home/tests/import-export-data/comma_separated_answers.csv index 9b078764..9d2e74db 100644 --- a/home/tests/import-export-data/comma_separated_answers.csv +++ b/home/tests/import-export-data/comma_separated_answers.csv @@ -1,2 +1,2 @@ -title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,answers,scores,semantic_ids -Comma Separated Answers,categorical_question,comma separated,comma-separated-answers,v1.0,en,high-inflection,3.0,medium-score,2.0,low-score,Generic error,Please choose your comma separated answer,We need to know this for a proper risk assessment,[],"""This, is, the, first"",""This, is, the, second""","3.0,2.0","test-1,test2" +title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,min,max,answers,scores,semantic_ids +Comma Separated Answers,categorical_question,comma separated,comma-separated-answers,v1.0,en,high-inflection,3.0,medium-score,2.0,low-score,Generic error,Please choose your comma separated answer,We need to know this for a proper risk assessment,[],,,"""This, is, the, first"",""This, is, the, second""","3.0,2.0","test-1,test2" diff --git a/home/tests/import-export-data/multiple_assessments.csv b/home/tests/import-export-data/multiple_assessments.csv index 32f20d50..e931d052 100644 --- a/home/tests/import-export-data/multiple_assessments.csv +++ b/home/tests/import-export-data/multiple_assessments.csv @@ -1,8 +1,9 @@ -title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,answers,scores,semantic_ids -Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the first question,We need to know this for a proper risk assessment,Please retry,"A,B","4.0,1.0","test-1,test-2" -Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the second question,We need to know this for a proper risk assessment,We did not quite get that,"A,B,C","1.0,3.0,4.0","test-1,test-2,test-3" -Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the third question,We need to know this for a proper risk assessment,Sorry we did not quite get that,"A,B,C","2.0,1.0,2.0","test-1,test-2,test-3" -Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know this for a proper risk assessment,Sorry we don't understand.,"Once a week,Twice a week,Thrice a week","1.0,3.0,4.5","test-1,test-2,test-3" -Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",Have you been vaccinated against COVID-19?,We need to know this for a proper risk assessment,Sorry we didn't quite catch that.,"Yes,No","3.0,1.0","test-1,test-2" -Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How high is your temperature?,We need to know this for a proper risk assessment,Please choose the option that matches your answer.,"Between 37.5C and 38C,Between 38.1C and 40C,Between 40.1C and 41.1C","3.0,2.0,1.0","test-1,test-2,test-3" -Freetext Test,freetext_question,Free-text,freetext-test,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,Generic error message,Did you find the information useful,We need to know if the information was useful,,,, +title,question_type,tags,slug,version,locale,high_result_page,high_inflection,medium_result_page,medium_inflection,low_result_page,generic_error,question,explainer,error,min,max,answers,scores,semantic_ids +Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the first question,We need to know this for a proper risk assessment,Please retry,,,"A,B","4.0,1.0","test-1,test-2" +Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the second question,We need to know this for a proper risk assessment,We did not quite get that,,,"A,B,C","1.0,3.0,4.0","test-1,test-2,test-3" +Random Choice,categorical_question,"Random,selection",random-choice,v1.0,en,high-inflection,4.0,medium-score,3.0,low-score,We did not quite get that,Select a number for the third question,We need to know this for a proper risk assessment,Sorry we did not quite get that,,,"A,B,C","2.0,1.0,2.0","test-1,test-2,test-3" +Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How often do you check your blood pressure,We need to know this for a proper risk assessment,Sorry we don't understand.,,,"Once a week,Twice a week,Thrice a week","1.0,3.0,4.5","test-1,test-2,test-3" +Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",Have you been vaccinated against COVID-19?,We need to know this for a proper risk assessment,Sorry we didn't quite catch that.,,,"Yes,No","3.0,1.0","test-1,test-2" +Health Assessment,categorical_question,checker,health-assessment,v1.0,en,high-inflection,4.0,medium-score,2.0,low-score,"Sorry, we didn't quite get that.",How high is your temperature?,We need to know this for a proper risk assessment,Please choose the option that matches your answer.,,,"Between 37.5C and 38C,Between 38.1C and 40C,Between 40.1C and 41.1C","3.0,2.0,1.0","test-1,test-2,test-3" +Freetext Test,freetext_question,Free-text,freetext-test,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,Generic error message,Did you find the information useful,We need to know if the information was useful,,,,,, +Integer Type Question,integer_question,integer-type-question,integer-type-question,v1.0,en,high-inflection,5.0,medium-score,3.0,low-score,This is a generic error,How much do you weigh in kilograms?,We need to test integer type questions,Sorry your min and max weight should be between 40 and 500kg.,40,500,,, diff --git a/home/tests/test_api.py b/home/tests/test_api.py index 897f2827..9bdcfd32 100644 --- a/home/tests/test_api.py +++ b/home/tests/test_api.py @@ -27,6 +27,7 @@ ContentPage, FreeTextQuestionBlock, HomePage, + IntegerQuestionBlock, MultiselectQuestionBlock, OrderedContentSet, PageView, @@ -1417,6 +1418,22 @@ def create_test_data(self): freetext_question_block_value, ) ) + integer_question_block = IntegerQuestionBlock() + integer_question_block_value = integer_question_block.to_python( + { + "question": "What's your weight in kilograms?", + "error": "Your weight should be between 40 and 500kg", + "min": 40, + "max": 500, + "answers": None, + } + ) + self.assessment.questions.append( + ( + "integer_question", + integer_question_block_value, + ) + ) self.assessment.save() def test_assessment_endpoint(self, uclient): @@ -1491,6 +1508,8 @@ def test_assessment_endpoint(self, uclient): "question": "What is the best chocolate?", "explainer": None, "error": "Invalid answer", + "min": None, + "max": None, "answers": [ {"answer": "Crunchie", "score": "5", "semantic_id": "crunchie"}, {"answer": "Flake", "score": "3", "semantic_id": "flake"}, @@ -1502,6 +1521,8 @@ def test_assessment_endpoint(self, uclient): "question": "How old are you?", "explainer": None, "error": "Invalid answer", + "min": None, + "max": None, "answers": [], } assert content["results"][0]["questions"][2] == { @@ -1510,6 +1531,8 @@ def test_assessment_endpoint(self, uclient): "question": "Which chocolates are yummy?", "explainer": None, "error": "Invalid answer", + "min": None, + "max": None, "answers": [ {"answer": "Crunchie", "score": "5", "semantic_id": "crunchie"}, {"answer": "Flake", "score": "3", "semantic_id": "flake"}, @@ -1521,6 +1544,18 @@ def test_assessment_endpoint(self, uclient): "question": "How useful is this information?", "explainer": None, "error": None, + "min": None, + "max": None, + "answers": [], + } + assert content["results"][0]["questions"][4] == { + "id": self.assessment.questions[4].id, + "question_type": "integer_question", + "question": "What's your weight in kilograms?", + "explainer": None, + "error": "Your weight should be between 40 and 500kg", + "min": 40, + "max": 500, "answers": [], } diff --git a/home/tests/test_serializers.py b/home/tests/test_serializers.py index 3079daa4..1f9bfaaf 100644 --- a/home/tests/test_serializers.py +++ b/home/tests/test_serializers.py @@ -130,8 +130,6 @@ def create_form_with_fields() -> Assessment: { "type": "categorical_question", "value": { - # "type": "categorical_question", - # "question_type": "categorical_question", "question": "test question", "explainer": "We need to know this", "error": "test error", @@ -479,6 +477,8 @@ def test_form_with_fields(self) -> None: "question": "test question", "explainer": "We need to know this", "error": "test error", + "min": None, + "max": None, "answers": [ {"score": 2.0, "answer": "A"}, {"score": 1.0, "answer": "B"}, @@ -503,6 +503,8 @@ def test_form_with_missing_fields(self) -> None: "question": "test question", "explainer": None, "error": "test error", + "min": None, + "max": None, "answers": [ {"score": 2.0, "answer": "A"}, {"score": 1.0, "answer": "B"},