def test_mutually_exclusive_mandatory_checkbox(answer_permutations,
                                               is_mandatory):
    validator = MutuallyExclusiveCheck(question_title="")
    validator(
        answer_values=iter(answer_permutations),
        is_mandatory=is_mandatory,
        is_only_checkboxes=True,
    )
def test_mutually_exclusive_mandatory_checkbox_raises_ValidationError(
        answer_permutations, is_mandatory, is_only_checkboxes, error_type):
    validator = MutuallyExclusiveCheck(question_title="")
    with pytest.raises(ValidationError) as exc:
        validator(
            answer_values=iter(answer_permutations),
            is_mandatory=is_mandatory,
            is_only_checkboxes=is_only_checkboxes,
        )

    assert format_message_with_title(error_messages[error_type],
                                     "") == str(exc.value)
Exemplo n.º 3
0
    def validate_mutually_exclusive_question(self, question):
        is_mandatory = question.get("mandatory")
        messages = (question["validation"].get("messages")
                    if "validation" in question else None)
        answers = (getattr(self, answer["id"]).data
                   for answer in question["answers"])

        validator = MutuallyExclusiveCheck(messages=messages)

        try:
            validator(answers, is_mandatory)
        except validators.ValidationError as e:
            self.question_errors[question["id"]] = str(e)
            return False

        return True
    def validate_mutually_exclusive_question(self,
                                             question: QuestionSchema) -> bool:
        is_mandatory: bool = question["mandatory"]
        messages = (question["validation"].get("messages")
                    if "validation" in question else None)
        answers = (getattr(self, answer["id"]).data
                   for answer in question["answers"])
        is_only_checkboxes = all(answer["type"] == "Checkbox"
                                 for answer in question["answers"])

        validator = MutuallyExclusiveCheck(
            messages=messages,
            question_title=self.question_title,
        )

        try:
            validator(answers, is_mandatory, is_only_checkboxes)
        except validators.ValidationError as e:
            self.question_errors[question["id"]] = str(e)

            return False
        return True
Exemplo n.º 5
0
 def setUp(self):
     self.validator = MutuallyExclusiveCheck()
 def setUp(self):
     self.question_title = ""
     self.validator = MutuallyExclusiveCheck(
         question_title=self.question_title)