def test_converter_checkboxes_with_q_codes_and_empty_other_value(
    fake_questionnaire_store, ):
    routing_path = RoutingPath(["crisps"], section_id="food")

    fake_questionnaire_store.answer_store = AnswerStore([
        Answer("crisps-answer", ["Ready salted", "Other"]).to_dict(),
        Answer("other-answer-mandatory", "").to_dict(),
    ])

    question = {
        "id":
        "crisps-question",
        "answers": [{
            "id":
            "crisps-answer",
            "type":
            "Checkbox",
            "options": [
                {
                    "label": "Ready salted",
                    "value": "Ready salted",
                    "q_code": "1"
                },
                {
                    "label": "Sweet chilli",
                    "value": "Sweet chilli",
                    "q_code": "2"
                },
                {
                    "label": "Cheese and onion",
                    "value": "Cheese and onion",
                    "q_code": "3",
                },
                {
                    "label": "Other",
                    "q_code": "4",
                    "description": "Choose any other flavour",
                    "value": "Other",
                    "detail_answer": {
                        "mandatory": True,
                        "id": "other-answer-mandatory",
                        "label": "Please specify other",
                        "type": "TextField",
                    },
                },
            ],
        }],
    }

    questionnaire = make_schema("0.0.1", "section-1", "favourite-food",
                                "crisps", question)

    # When
    answer_object = convert_answers(QuestionnaireSchema(questionnaire),
                                    fake_questionnaire_store, routing_path)

    # Then
    assert len(answer_object["data"]) == 2
    assert answer_object["data"]["1"] == "Ready salted"
    assert answer_object["data"]["4"] == "Other"
コード例 #2
0
def test_month_year_date_answer(fake_questionnaire_store):
    full_routing_path = [RoutingPath(["date-block"], section_id="section-1")]
    answers = AnswerStore(
        [
            Answer("single-date-answer", "01-01-1990").to_dict(),
            Answer("month-year-answer", "01-1990").to_dict(),
        ]
    )
    fake_questionnaire_store.answer_store = answers

    questionnaire = make_schema(
        "0.0.3",
        "section-1",
        "date-group",
        "date-block",
        {
            "id": "month-year-question",
            "answers": [{"id": "month-year-answer", "type": "MonthYearDate"}],
        },
    )

    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire),
        fake_questionnaire_store,
        full_routing_path,
        SUBMITTED_AT,
    )

    assert len(answer_object["data"]["answers"]) == 1

    assert answer_object["data"]["answers"][0].value == "01-1990"
コード例 #3
0
def test_answer_source_not_on_path_non_repeating_section(is_answer_on_path):
    schema = get_mock_schema()

    location = Location(section_id="test-section", block_id="test-block")

    if is_answer_on_path:
        schema.get_block_for_answer_id = Mock(
            return_value={"id": "block-on-path"})
        answer_id = "answer-on-path"
        expected_result = True
    else:
        schema.get_block_for_answer_id = Mock(
            return_value={"id": "block-not-on-path"})
        answer_id = "answer-not-on-path"
        expected_result = False

    answer = Answer(answer_id=answer_id, value="Yes")

    rule_evaluator = get_rule_evaluator(
        schema=schema,
        answer_store=AnswerStore([answer.to_dict()]),
        location=location,
        routing_path_block_ids=["block-on-path"],
    )

    assert (rule_evaluator.evaluate(
        rule={
            Operator.EQUAL: [
                "Yes",
                {
                    "source": "answers",
                    "identifier": "answer-on-path"
                },
            ]
        }) == expected_result)
def test_answer_source_with_routing_path_block_ids_outside_repeat(
        is_answer_on_path):
    schema = get_mock_schema()

    location = Location(section_id="test-section", block_id="test-block")

    if is_answer_on_path:
        schema.get_block_for_answer_id = Mock(
            return_value={"id": f"block-on-path"})
        answer_id = "answer-on-path"
        expected_result = "Yes"
    else:
        schema.get_block_for_answer_id = Mock(
            return_value={"id": f"block-not-on-path"})
        answer_id = "answer-not-on-path"
        expected_result = None

    answer = Answer(answer_id=answer_id, value="Yes")

    value_source_resolver = get_value_source_resolver(
        schema=schema,
        answer_store=AnswerStore([answer.to_dict()]),
        list_store=ListStore([{
            "name": "some-list",
            "items": get_list_items(3)
        }]),
        location=location,
        list_item_id=location.list_item_id,
        routing_path_block_ids=["block-on-path"],
    )

    assert (value_source_resolver.resolve({
        "source": "answers",
        "identifier": "answer-on-path"
    }) == expected_result)
コード例 #5
0
def test_convert_answers_to_payload_0_0_3(fake_questionnaire_store):
    full_routing_path = [
        RoutingPath(["about you", "where you live"], section_id="household-section")
    ]

    fake_questionnaire_store.answer_store = AnswerStore(
        [
            Answer("name", "Joe Bloggs", None).to_dict(),
            Answer("address", "62 Somewhere", None).to_dict(),
        ]
    )

    questionnaire = {
        "survey_id": "021",
        "data_version": "0.0.3",
        "sections": [
            {
                "id": "household-section",
                "groups": [
                    {
                        "id": "personal details",
                        "blocks": [
                            {
                                "id": "about you",
                                "type": "Question",
                                "question": {
                                    "id": "crisps-question",
                                    "answers": [{"id": "name", "type": "TextField"}],
                                },
                            }
                        ],
                    },
                    {
                        "id": "household",
                        "blocks": [
                            {
                                "id": "where you live",
                                "type": "Question",
                                "question": {
                                    "id": "crisps-question",
                                    "answers": [{"id": "address", "type": "TextField"}],
                                },
                            }
                        ],
                    },
                ],
            }
        ],
    }

    # When
    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire), fake_questionnaire_store, full_routing_path
    )

    # Then
    assert len(answer_object["data"]["answers"]) == 2
    assert answer_object["data"]["answers"][0].value == "Joe Bloggs"
    assert answer_object["data"]["answers"][1].value, "62 Somewhere"
コード例 #6
0
def fake_questionnaire_store():
    storage = Mock()
    storage.get_user_data = Mock(return_value=("{}", "ce_sid", 1, None))
    questionnaire_store = QuestionnaireStore(storage)
    questionnaire_store.submitted_at = SUBMITTED_AT
    questionnaire_store.metadata = {"tx_id": "123456789", "ru_name": "Apple"}
    questionnaire_store.answer_store = AnswerStore(
        [
            Answer("name-answer", "John Smith", None).to_dict(),
            Answer("address-answer", "NP10 8XG", None).to_dict(),
        ]
    )
    return questionnaire_store
コード例 #7
0
def test_unit_answer(fake_questionnaire_store):
    full_routing_path = [
        RoutingPath(["unit-block"], section_id="section-1", list_item_id=None)
    ]
    fake_questionnaire_store.answer_store = AnswerStore(
        [Answer("unit-answer", 10).to_dict()])

    question = {
        "id": "unit-question",
        "answers": [{
            "id": "unit-answer",
            "type": "Unit",
            "q_code": "1"
        }],
    }

    questionnaire = make_schema("0.0.1", "section-1", "unit-block",
                                "unit-block", question)

    # When
    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire),
        fake_questionnaire_store,
        full_routing_path,
        SUBMITTED_AT,
    )

    # Then
    assert len(answer_object["data"]) == 1
    assert answer_object["data"]["1"] == "10"
コード例 #8
0
def test_textarea_answer(fake_questionnaire_store):
    full_routing_path = [RoutingPath(["textarea-block"], section_id="section-1")]
    answers = AnswerStore(
        [Answer("textarea-answer", "This is an example text!").to_dict()]
    )
    fake_questionnaire_store.answer_store = answers

    questionnaire = make_schema(
        "0.0.3",
        "section-1",
        "textarea-group",
        "textarea-block",
        {
            "id": "textarea-question",
            "answers": [{"id": "textarea-answer", "type": "TextArea"}],
        },
    )

    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire),
        fake_questionnaire_store,
        full_routing_path,
        SUBMITTED_AT,
    )

    assert len(answer_object["data"]["answers"]) == 1
    assert answer_object["data"]["answers"][0].value == "This is an example text!"
コード例 #9
0
def test_answer_without_qcode(fake_questionnaire_store):
    fake_questionnaire_store.answer_store = AnswerStore(
        [Answer("GHI", "String test + !").to_dict()])

    question = {
        "id": "question-2",
        "answers": [{
            "id": "GHI",
            "type": "TextField"
        }]
    }

    questionnaire = make_schema("0.0.1", "section-1", "group-1", "block-1",
                                question)

    full_routing_path = [
        RoutingPath(["block-1"], section_id="section-1", list_item_id=None)
    ]

    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire),
        fake_questionnaire_store,
        full_routing_path,
        SUBMITTED_AT,
    )

    assert not answer_object["data"]
コード例 #10
0
def test_unit_answer(fake_questionnaire_store):
    full_routing_path = [RoutingPath(["unit-block"], section_id="section-1")]
    answers = AnswerStore([Answer("unit-answer", 10).to_dict()])
    fake_questionnaire_store.answer_store = answers

    questionnaire = make_schema(
        "0.0.3",
        "section-1",
        "unit-group",
        "unit-block",
        {
            "id": "unit-question",
            "answers": [{
                "id": "unit-answer",
                "type": "Unit"
            }]
        },
    )

    answer_object = convert_answers(QuestionnaireSchema(questionnaire),
                                    fake_questionnaire_store,
                                    full_routing_path)

    assert len(answer_object["data"]["answers"]) == 1
    assert answer_object["data"]["answers"][0].value == 10
コード例 #11
0
def test_minimum_and_maximum_offset_dates(app, value_source_resolver, rule_evaluator):
    value_source_resolver.metadata = {"date": "2018-02-20"}
    answer_store = AnswerStore()

    test_answer_id = Answer(answer_id="date", value="2018-03-20")
    answer_store.add_or_update(test_answer_id)
    value_source_resolver.answer_store = answer_store
    answer = {
        "id": "date_answer",
        "type": "Date",
        "minimum": {
            "value": {"identifier": "date", "source": "metadata"},
            "offset_by": {"days": -10},
        },
        "maximum": {
            "value": {"identifier": "date", "source": "answers"},
            "offset_by": {"years": 1},
        },
    }

    handler = DateHandler(answer, value_source_resolver, rule_evaluator, error_messages)
    minimum_date = handler.get_date_value("minimum")
    maximum_date = handler.get_date_value("maximum")

    assert minimum_date == parse_datetime("2018-02-10")
    assert maximum_date == parse_datetime("2019-03-20")
コード例 #12
0
def test_get_referenced_offset_value_with_list_item_id(
    app, value_source_resolver, rule_evaluator
):
    list_item_id = "abcde"

    test_answer_id = Answer(
        answer_id="date", value="2018-03-20", list_item_id=list_item_id
    )

    location = Location(section_id="test", list_item_id=list_item_id)

    answer_store = AnswerStore()

    answer_store.add_or_update(test_answer_id)
    value_source_resolver.answer_store = answer_store
    value_source_resolver.location = location
    value_source_resolver.list_item_id = list_item_id
    answer = {
        "maximum": {
            "value": {"identifier": "date", "source": "answers"},
            "offset_by": {"months": 1},
        }
    }

    handler = DateHandler(answer, value_source_resolver, rule_evaluator, error_messages)
    maximum_date = handler.get_date_value("maximum")

    assert maximum_date == parse_datetime("2018-04-20")
def test_percentage_answer(fake_questionnaire_store):
    routing_path = RoutingPath(["percentage-block"], section_id="section-1")
    fake_questionnaire_store.answer_store = AnswerStore(
        [Answer("percentage-answer", 100).to_dict()])

    question = {
        "id":
        "percentage-question",
        "answers": [{
            "id": "percentage-answer",
            "type": "Percentage",
            "q_code": "1"
        }],
    }

    questionnaire = make_schema("0.0.1", "section-1", "percentage-block",
                                "percentage-block", question)

    # When
    answer_object = convert_answers(QuestionnaireSchema(questionnaire),
                                    fake_questionnaire_store, routing_path)

    # Then
    assert len(answer_object["data"]) == 1
    assert answer_object["data"]["1"] == "100"
コード例 #14
0
def test_answer_with_float(fake_questionnaire_store):
    fake_questionnaire_store.answer_store = AnswerStore(
        [Answer("GHI", 10.02).to_dict()])

    question = {
        "id": "question-2",
        "answers": [{
            "id": "GHI",
            "type": "TextField",
            "q_code": "003"
        }],
    }

    questionnaire = make_schema("0.0.1", "section-1", "group-1", "block-1",
                                question)

    full_routing_path = [
        RoutingPath(["block-1"], section_id="section-1", list_item_id=None)
    ]

    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire),
        fake_questionnaire_store,
        full_routing_path,
        SUBMITTED_AT,
    )

    # Check the converter correctly
    assert answer_object["data"]["003"] == "10.02"
コード例 #15
0
def test_currency_answer(fake_questionnaire_store):
    full_routing_path = [RoutingPath(["currency-block"], section_id="section-1")]
    answers = AnswerStore([Answer("currency-answer", 100).to_dict()])
    fake_questionnaire_store.answer_store = answers

    questionnaire = make_schema(
        "0.0.3",
        "section-1",
        "currency-group",
        "currency-block",
        {
            "id": "currency-question",
            "answers": [{"id": "currency-answer", "type": "Currency"}],
        },
    )

    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire),
        fake_questionnaire_store,
        full_routing_path,
        SUBMITTED_AT,
    )

    assert len(answer_object["data"]["answers"]) == 1
    assert answer_object["data"]["answers"][0].value == 100
コード例 #16
0
def test_radio_answer(fake_questionnaire_store):
    full_routing_path = [RoutingPath(["radio-block"], section_id="section-1")]
    answers = AnswerStore([Answer("radio-answer", "Coffee").to_dict()])
    fake_questionnaire_store.answer_store = answers

    questionnaire = make_schema(
        "0.0.3",
        "section-1",
        "radio-group",
        "radio-block",
        {
            "id": "radio-question",
            "answers": [
                {
                    "type": "Radio",
                    "id": "radio-answer",
                    "options": [
                        {"label": "Coffee", "value": "Coffee"},
                        {"label": "Tea", "value": "Tea"},
                    ],
                }
            ],
        },
    )

    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire),
        fake_questionnaire_store,
        full_routing_path,
        SUBMITTED_AT,
    )

    assert len(answer_object["data"]["answers"]) == 1
    assert answer_object["data"]["answers"][0].value == "Coffee"
コード例 #17
0
def test_get_referenced_offset_value_with_list_item_id(app, schema_mock):
    list_item_id = "abcde"
    answer_store = AnswerStore()

    test_answer_id = Answer(answer_id="date",
                            value="2018-03-20",
                            list_item_id=list_item_id)

    location = Location(section_id="test", list_item_id=list_item_id)

    answer_store.add_or_update(test_answer_id)

    answer = {
        "maximum": {
            "value": {
                "identifier": "date",
                "source": "answers"
            },
            "offset_by": {
                "months": 1
            },
        }
    }

    handler = DateHandler(answer, answer_store=answer_store, location=location)
    maximum_date = handler.get_date_value("maximum")

    assert maximum_date == convert_to_datetime("2018-04-20")
コード例 #18
0
def test_convert_payload_0_0_3_multiple_answers(fake_questionnaire_store):
    full_routing_path = [RoutingPath(["crisps"], section_id="section-1")]
    answers = AnswerStore(
        [Answer("crisps-answer", ["Ready salted", "Sweet chilli"]).to_dict()]
    )
    fake_questionnaire_store.answer_store = answers

    questionnaire = make_schema(
        "0.0.3",
        "section-1",
        "favourite-food",
        "crisps",
        {
            "id": "crisps-question",
            "answers": [
                {
                    "id": "crisps-answer",
                    "type": "Checkbox",
                    "options": [
                        {"label": "Ready salted", "value": "Ready salted"},
                        {"label": "Sweet chilli", "value": "Sweet chilli"},
                        {"label": "Cheese and onion", "value": "Cheese and onion"},
                    ],
                }
            ],
        },
    )

    # When
    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire), fake_questionnaire_store, full_routing_path
    )
    # Then
    assert len(answer_object["data"]["answers"]) == 1
    assert answer_object["data"]["answers"][0].value == ["Ready salted", "Sweet chilli"]
コード例 #19
0
def test_dropdown_answer(fake_questionnaire_store):
    full_routing_path = [RoutingPath(["dropdown-block"], section_id="section-1")]
    answers = AnswerStore([Answer("dropdown-answer", "Rugby is better!").to_dict()])
    fake_questionnaire_store.answer_store = answers

    questionnaire = make_schema(
        "0.0.3",
        "section-1",
        "dropdown-group",
        "dropdown-block",
        {
            "id": "dropdown-question",
            "answers": [
                {
                    "id": "dropdown-answer",
                    "type": "Dropdown",
                    "options": [
                        {"label": "Liverpool", "value": "Liverpool"},
                        {"label": "Chelsea", "value": "Chelsea"},
                        {"label": "Rugby is better!", "value": "Rugby is better!"},
                    ],
                }
            ],
        },
    )

    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire), fake_questionnaire_store, full_routing_path
    )

    # Then
    assert len(answer_object["data"]["answers"]) == 1
    assert answer_object["data"]["answers"][0].value == "Rugby is better!"
コード例 #20
0
    def get_default_answer(self, answer_id):
        try:
            answer_schema = self.get_answers_by_answer_id(answer_id)[0]
            answer = Answer(answer_schema["id"], answer_schema["default"])
        except (KeyError, TypeError):
            return None

        return answer
コード例 #21
0
def test_convert_answers_to_payload_0_0_1_with_key_error(
        fake_questionnaire_store):
    fake_questionnaire_store.answer_store = AnswerStore([
        Answer("ABC", "2016-01-01").to_dict(),
        Answer("DEF", "2016-03-30").to_dict(),
        Answer("GHI", "2016-05-30").to_dict(),
    ])

    question = {
        "id":
        "question-1",
        "answers": [
            {
                "id": "LMN",
                "type": "TextField",
                "q_code": "001"
            },
            {
                "id": "DEF",
                "type": "TextField",
                "q_code": "002"
            },
            {
                "id": "JKL",
                "type": "TextField",
                "q_code": "003"
            },
        ],
    }

    questionnaire = make_schema("0.0.1", "section-1", "group-1", "block-1",
                                question)

    full_routing_path = [
        RoutingPath(["block-1"], section_id="section-1", list_item_id=None)
    ]
    answer_object = convert_answers_to_payload_0_0_1(
        fake_questionnaire_store.metadata,
        fake_questionnaire_store.response_metadata,
        fake_questionnaire_store.answer_store,
        fake_questionnaire_store.list_store,
        QuestionnaireSchema(questionnaire),
        full_routing_path,
    )
    assert answer_object["002"] == "2016-03-30"
    assert len(answer_object) == 1
コード例 #22
0
 def get_default_answer(self, answer_id: str) -> Optional[Answer]:
     if answer_schemas := self.get_answers_by_answer_id(answer_id):
         first_answer_schema = answer_schemas[0]
         try:
             return Answer(first_answer_schema["id"],
                           first_answer_schema["default"])
         except (IndexError, KeyError, TypeError):
             return None
コード例 #23
0
def test_converter_q_codes_for_empty_strings(fake_questionnaire_store):
    full_routing_path = [
        RoutingPath(["crisps"], section_id="food", list_item_id=None)
    ]
    fake_questionnaire_store.answer_store = AnswerStore([
        Answer("crisps-answer", "").to_dict(),
        Answer("other-crisps-answer", "Ready salted").to_dict(),
    ])

    question = {
        "id":
        "crisps-question",
        "answers": [
            {
                "id": "crisps-answer",
                "type": "TextArea",
                "options": [],
                "q_code": "1"
            },
            {
                "id": "other-crisps-answer",
                "type": "TextArea",
                "options": [],
                "q_code": "2",
            },
        ],
    }

    questionnaire = make_schema("0.0.1", "section-1", "favourite-food",
                                "crisps", question)

    # When
    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire),
        fake_questionnaire_store,
        full_routing_path,
        SUBMITTED_AT,
    )

    # Then
    assert len(answer_object["data"]) == 1
    assert answer_object["data"]["2"] == "Ready salted"
コード例 #24
0
def test_get_schema_value_answer_store(value_source_resolver, rule_evaluator):
    answer_schema = {
        "id": "test-range",
        "label": "",
        "description": "Range Test",
        "mandatory": False,
        "type": "Number",
        "decimal_places": 2,
        "maximum": {
            "value": {
                "identifier": "set-maximum",
                "source": "answers"
            }
        },
        "minimum": {
            "value": {
                "identifier": "set-minimum",
                "source": "answers"
            }
        },
    }
    value_source_resolver.metadata = {
        "schema_name": "test_numbers",
        "language_code": "en",
    }
    answer_store = AnswerStore()

    answer_store.add_or_update(Answer(answer_id="set-maximum", value=10))
    answer_store.add_or_update(Answer(answer_id="set-minimum", value=1))
    value_source_resolver.answer_store = answer_store
    number_handler = NumberHandler(answer_schema, value_source_resolver,
                                   rule_evaluator, error_messages)

    maximum = number_handler.get_schema_value(answer_schema["maximum"])
    minimum = number_handler.get_schema_value(answer_schema["minimum"])

    assert maximum == 10
    assert minimum == 1
コード例 #25
0
def test_dropdown_answer(fake_questionnaire_store):
    full_routing_path = [
        RoutingPath(["dropdown-block"],
                    section_id="section-1",
                    list_item_id=None)
    ]
    fake_questionnaire_store.answer_store = AnswerStore(
        [Answer("dropdown-answer", "Liverpool").to_dict()])

    question = {
        "id":
        "dropdown-question",
        "answers": [{
            "id":
            "dropdown-answer",
            "type":
            "Dropdown",
            "q_code":
            "1",
            "options": [
                {
                    "label": "Liverpool",
                    "value": "Liverpool"
                },
                {
                    "label": "Chelsea",
                    "value": "Chelsea"
                },
                {
                    "label": "Rugby is better!",
                    "value": "Rugby is better!"
                },
            ],
        }],
    }

    questionnaire = make_schema("0.0.1", "section-1", "dropdown-block",
                                "dropdown-block", question)

    # When
    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire),
        fake_questionnaire_store,
        full_routing_path,
        SUBMITTED_AT,
    )

    # Then
    assert len(answer_object["data"]) == 1
    assert answer_object["data"]["1"] == "Liverpool"
コード例 #26
0
def fake_questionnaire_store(fake_metadata, fake_collection_metadata):
    user_answer = Answer(answer_id="GHI", value=0, list_item_id=None)

    storage = MagicMock()
    storage.get_user_data = MagicMock(return_value=("{}", 1))
    storage.add_or_update = MagicMock()

    store = QuestionnaireStore(storage)

    store.answer_store = AnswerStore()
    store.answer_store.add_or_update(user_answer)
    store.metadata = fake_metadata
    store.collection_metadata = fake_collection_metadata

    return store
コード例 #27
0
def test_get_referenced_offset_value_for_answer_id(
    app, value_source_resolver, rule_evaluator
):
    answer_store = AnswerStore()

    test_answer_id = Answer(answer_id="date", value="2018-03-20")
    answer_store.add_or_update(test_answer_id)
    value_source_resolver.answer_store = answer_store
    answer = {"maximum": {"value": {"identifier": "date", "source": "answers"}}}

    handler = DateHandler(answer, value_source_resolver, rule_evaluator, error_messages)
    maximum_date = handler.get_date_value("maximum")
    maximum_date = handler.transform_date_by_offset(maximum_date, {"months": 1})

    assert maximum_date == parse_datetime("2018-04-20")
def test_answer_source_default_answer(use_default_answer):
    schema = get_mock_schema()
    if use_default_answer:
        schema.get_default_answer = Mock(
            return_value=Answer(answer_id="some-answer", value="Yes"))
    else:
        schema.get_default_answer = Mock(return_value=None)

    value_source_resolver = get_value_source_resolver(
        schema=schema,
        use_default_answer=use_default_answer,
    )

    expected_result = "Yes" if use_default_answer else None
    assert (value_source_resolver.resolve({
        "source": "answers",
        "identifier": "some-answer"
    }) == expected_result)
コード例 #29
0
def test_radio_answer(fake_questionnaire_store):
    full_routing_path = [
        RoutingPath(["radio-block"], section_id="section-1", list_item_id=None)
    ]
    fake_questionnaire_store.answer_store = AnswerStore(
        [Answer("radio-answer", "Coffee").to_dict()])

    question = {
        "id":
        "radio-question",
        "answers": [{
            "type":
            "Radio",
            "id":
            "radio-answer",
            "q_code":
            "1",
            "options": [
                {
                    "label": "Coffee",
                    "value": "Coffee"
                },
                {
                    "label": "Tea",
                    "value": "Tea"
                },
            ],
        }],
    }
    questionnaire = make_schema("0.0.1", "section-1", "radio-block",
                                "radio-block", question)

    # When
    answer_object = convert_answers(
        QuestionnaireSchema(questionnaire),
        fake_questionnaire_store,
        full_routing_path,
        SUBMITTED_AT,
    )

    # Then
    assert len(answer_object["data"]) == 1
    assert answer_object["data"]["1"] == "Coffee"
コード例 #30
0
def test_get_referenced_offset_value_for_answer_id(app):
    answer_store = AnswerStore()

    test_answer_id = Answer(answer_id="date", value="2018-03-20")
    answer_store.add_or_update(test_answer_id)

    answer = {
        "maximum": {
            "value": {
                "identifier": "date",
                "source": "answers"
            }
        }
    }

    handler = DateHandler(answer, answer_store=answer_store)
    maximum_date = handler.get_date_value("maximum")
    maximum_date = handler.transform_date_by_offset(maximum_date,
                                                    {"months": 1})

    assert maximum_date == convert_to_datetime("2018-04-20")