def test_invalid_repeating_section_title_placeholders(): placeholder_container = { "text": "{person}", "placeholders": [ { "placeholder": "person_name", "transforms": [ { "transform": "concatenate_list", "arguments": { "list_to_concatenate": [ {"source": "answers", "identifier": "first-name"}, {"source": "answers", "identifier": "last-name"}, ], "delimiter": " ", }, } ], } ], } validator = PlaceholderValidator({}) validator.validate_placeholder_object(placeholder_container) expected_errors = [ { "message": validator.PLACEHOLDERS_DONT_MATCH_DEFINITIONS, "text": "{person}", "differences": {"person"}, } ] assert validator.errors == expected_errors
def test_placeholder_plurals(): placeholder_container = { "text_plural": { "forms": { "one": "You’ve said one person lives here. Is that correct?", "other": "You’ve said {number_of_people} people live here. Is that correct?", }, "count": { "source": "answers", "identifier": "answer1" }, }, "placeholders": [{ "placeholder": "number_of_persons", "transforms": [{ "transform": "number_to_words", "arguments": { "number": { "source": "answers", "identifier": "answer1" } }, }], }], } validator = PlaceholderValidator({}) validator.validate_placeholder_object(placeholder_container) expected_errors = [{ "message": validator.PLACEHOLDERS_DONT_MATCH_DEFINITIONS, "text": "You’ve said {number_of_people} people live here. Is that correct?", "differences": {"number_of_people"}, }] assert validator.errors == expected_errors
def validate(self): metadata_validator = MetadataValidator(self.schema_element["metadata"], self.schema_element["theme"]) self.errors += metadata_validator.validate() placeholder_validator = PlaceholderValidator(self.schema_element) self.errors += placeholder_validator.validate() self.validate_duplicates() self.validate_smart_quotes() for section in self.questionnaire_schema.sections: section_validator = SectionValidator(section, self.questionnaire_schema) self.errors += section_validator.validate() required_hub_section_ids = self.schema_element["questionnaire_flow"][ "options"].get("required_completed_sections", []) self.validate_required_section_ids( self.questionnaire_schema.section_ids, required_hub_section_ids) return self.errors
def test_validation_option_label_from_value(answer_id, expected_error): filename = "schemas/invalid/test_invalid_placeholder_option_label_from_value.json" schema_file = _open_and_load_schema_file(filename) validator = PlaceholderValidator(schema_file) validator.validate_option_label_from_value_placeholder(answer_id) assert validator.errors == expected_error