Exemplo n.º 1
0
def test_no_answer_label_multiple_answers():
    question = {
        "id":
        "some-question",
        "title":
        "Some title",
        "type":
        "General",
        "answers": [
            {
                "id": "number-1",
                "label": "Enter the first number",
                "mandatory": False,
                "type": "Number",
            },
            {
                "id": "number-2",
                "mandatory": False,
                "type": "Number"
            },
        ],
    }

    validator = get_question_validator(question)
    validator.validate()

    expected_error_messages = [{
        "message": validator.ANSWER_LABEL_MISSING_MULTIPLE_ANSWERS,
        "answer_id": "number-2",
        "question_id": "some-question",
    }]

    assert expected_error_messages == validator.errors
    def validate_question(self, block_or_variant):
        question = block_or_variant.get("question")
        routing_rules = block_or_variant.get("routing_rules", {})

        if question:
            question_validator = get_question_validator(question)

            self.errors += question_validator.validate()

            for answer in question.get("answers", []):
                if routing_rules:
                    answer_routing_validator = AnswerRoutingValidator(
                        answer, routing_rules)
                    self.errors += answer_routing_validator.validate()

                answer_validator = get_answer_validator(
                    answer, self.questionnaire_schema)

                answer_validator.validate()

                if question.get("summary") and answer["type"] not in [
                        "TextField",
                        "Checkbox",
                        "Number",
                ]:
                    self.add_error(
                        error_messages.
                        UNSUPPPORTED_QUESTION_SUMMARY_ANSWER_TYPE,
                        answer_id=answer["id"],
                    )
                self.errors += answer_validator.errors
Exemplo n.º 3
0
def test_no_answer_label_single_answer():
    question = {
        "id": "some-question",
        "title": "Some title",
        "type": "General",
        "answers": [{
            "id": "number-1",
            "mandatory": False,
            "type": "Number"
        }],
    }

    validator = get_question_validator(question)
    validator.validate()

    assert not validator.errors
Exemplo n.º 4
0
def test_no_answer_label_mutually_exclusive():
    question = {
        "id":
        "some-question",
        "title":
        "Some title",
        "type":
        "MutuallyExclusive",
        "answers": [
            {
                "type":
                "Checkbox",
                "id":
                "answer",
                "mandatory":
                False,
                "options": [
                    {
                        "label": "Option 1",
                        "value": "Option 1"
                    },
                    {
                        "label": "Option 2",
                        "value": "Option 2"
                    },
                ],
            },
            {
                "id":
                "answer-exclusive",
                "mandatory":
                False,
                "options": [{
                    "label": "None of the these apply",
                    "value": "None of the these apply",
                }],
                "type":
                "Checkbox",
            },
        ],
    }

    validator = get_question_validator(question)
    validator.validate()

    assert not validator.errors
Exemplo n.º 5
0
def test_no_answer_label_two_answers_last_answer_single_checkbox():
    question = {
        "id":
        "some-question",
        "title":
        "Some title",
        "type":
        "General",
        "answers": [
            {
                "id":
                "cost",
                "mandatory":
                False,
                "type":
                "Radio",
                "options": [
                    {
                        "label": "100",
                        "value": "100"
                    },
                    {
                        "label": "1000",
                        "value": "1000"
                    },
                ],
            },
            {
                "id":
                "age-estimate",
                "mandatory":
                False,
                "options": [{
                    "label": "This is an estimate",
                    "value": "This is an estimate"
                }],
                "type":
                "Checkbox",
            },
        ],
    }

    validator = get_question_validator(question)
    validator.validate()

    assert not validator.errors