def validate_variants(self, block): question_variants = block.get("question_variants", []) content_variants = block.get("content_variants", []) all_variants = question_variants + content_variants for variant in question_variants: self.validate_question(variant) # This is validated in json schema, but the error message is not good at the moment. if len(question_variants) == 1 or len(content_variants) == 1: self.add_error( error_messages.VARIANTS_HAS_ONE_VARIANT, block_id=block["id"] ) for variant in all_variants: when_clause = variant.get("when", []) if isinstance(when_clause, list): when_validator = WhenRuleValidator( when_clause, block["id"], self.questionnaire_schema ) self.errors += when_validator.validate() elif isinstance(when_clause, dict): when_validator = NewWhenRuleValidator( when_clause, self.section["id"], self.questionnaire_schema ) self.errors += when_validator.validate() self.validate_variant_fields(block, question_variants)
def validate_routing_rule(self, rule): rule = rule.get("goto") if rule and "when" in rule: when_validator = WhenRuleValidator(rule["when"], self.schema_element["id"], self.questionnaire_schema) self.errors += when_validator.validate()
def validate_section_enabled(self): section_enabled = self.section.get("enabled", None) if isinstance(section_enabled, list): for enabled in section_enabled: when = enabled["when"] when_validator = WhenRuleValidator( when, self.section["id"], self.questionnaire_schema ) self.errors += when_validator.validate() elif isinstance(section_enabled, dict): when = section_enabled["when"] when_validator = NewWhenRuleValidator( when, self.section["id"], self.questionnaire_schema ) self.errors += when_validator.validate()
def validate_skip_condition(self, skip_condition): """ Validate skip condition is valid :return: list of dictionaries containing error messages, otherwise it returns an empty list """ when = skip_condition.get("when") when_validator = WhenRuleValidator( when, self.schema_element["id"], self.questionnaire_schema ) self.errors += when_validator.validate()
def validate_skip_conditions(self, skip_conditions, origin_id): for skip_condition in skip_conditions: when_validator = WhenRuleValidator( skip_condition["when"], origin_id, self.questionnaire_schema ) self.errors += when_validator.validate()