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)
Ejemplo n.º 2
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)