Ejemplo n.º 1
0
def test_default_answers_not_present_when_not_answered(
        fake_questionnaire_store):
    """Test that default values aren't submitted downstream when an answer with
    a default value is not present in the answer store."""
    schema = load_schema("test_view_submitted_response")

    answer_objects = [
        {
            "answer_id": "test-currency",
            "value": "12"
        },
        {
            "answer_id": "square-kilometres",
            "value": "345"
        },
        {
            "answer_id": "test-decimal",
            "value": "67.89"
        },
    ]

    fake_questionnaire_store.answer_store = AnswerStore(answer_objects)
    fake_questionnaire_store.list_store = ListStore()

    routing_path = [
        RoutingPath(["radio", "test-number-block"],
                    section_id="default-section")
    ]

    output = convert_answers(schema, fake_questionnaire_store, routing_path)
    data = json.loads(json.dumps(output["data"]["answers"], for_json=True))

    answer_ids = {answer["answer_id"] for answer in data}
    assert "radio-answer" not in answer_ids
Ejemplo n.º 2
0
def test_list_structure_in_payload_is_as_expected(fake_questionnaire_store):
    routing_path = [
        RoutingPath(["primary-person-list-collector", "list-collector"],
                    section_id="section-1")
    ]

    answer_objects = [
        {
            "answer_id": "you-live-here",
            "value": "Yes"
        },
        {
            "answer_id": "first-name",
            "value": "1",
            "list_item_id": "xJlKBy"
        },
        {
            "answer_id": "last-name",
            "value": "1",
            "list_item_id": "xJlKBy"
        },
        {
            "answer_id": "first-name",
            "value": "2",
            "list_item_id": "RfAGDc"
        },
        {
            "answer_id": "last-name",
            "value": "2",
            "list_item_id": "RfAGDc"
        },
        {
            "answer_id": "anyone-else",
            "value": "No"
        },
    ]

    answers = AnswerStore(answer_objects)

    list_store = ListStore(existing_items=[{
        "name": "people",
        "items": ["xJlKBy", "RfAGDc"],
        "primary_person": "xJlKBy",
    }])

    fake_questionnaire_store.answer_store = answers
    fake_questionnaire_store.list_store = list_store

    schema = load_schema("test_list_collector_primary_person")

    output = convert_answers(schema, fake_questionnaire_store, routing_path)

    data_dict = json.loads(json.dumps(output["data"]["lists"], for_json=True))

    assert data_dict[0]["name"] == "people"
    assert "xJlKBy" in data_dict[0]["items"]
    assert data_dict[0]["primary_person"] == "xJlKBy"
Ejemplo n.º 3
0
def test_list_item_conversion_empty_list(fake_questionnaire_store):
    """ Test that the list store is populated with an empty list for lists which
    do not have answers yet."""
    routing_path = [
        RoutingPath(
            [
                "list-collector",
                "next-interstitial",
                "another-list-collector-block",
                "group-summary",
            ],
            section_id="section-1",
        )
    ]

    answer_objects = [
        {
            "answer_id": "last-name",
            "value": "2",
            "list_item_id": "RfAGDc"
        },
        {
            "answer_id": "anyone-else",
            "value": "No"
        },
        {
            "answer_id": "another-anyone-else",
            "value": "No"
        },
        {
            "answer_id": "extraneous-answer",
            "value": "Bad",
            "list_item_id": "123"
        },
    ]

    fake_questionnaire_store.answer_store = AnswerStore(answer_objects)
    fake_questionnaire_store.list_store = ListStore()

    schema = load_schema("test_list_collector")

    output = convert_answers(schema, fake_questionnaire_store, routing_path)

    # Answers not on the routing path
    del answer_objects[0]
    del answer_objects[-1]

    data_dict = json.loads(json.dumps(output["data"]["answers"],
                                      for_json=True))

    assert sorted(answer_objects, key=lambda x: x["answer_id"]) == sorted(
        data_dict, key=lambda x: x["answer_id"])
Ejemplo n.º 4
0
def test_default_answers_not_present_when_not_answered(
        fake_questionnaire_store):
    """Test that default values aren't submitted downstream when an answer with
    a default value is not present in the answer store."""
    schema = load_schema("test_default")

    answer_objects = [{"answer_id": "number-question-two", "value": "12"}]

    fake_questionnaire_store.answer_store = AnswerStore(answer_objects)
    fake_questionnaire_store.list_store = ListStore()

    routing_path = [
        RoutingPath(["number-question-one", "number-question-two"],
                    section_id="default-section")
    ]

    output = convert_answers(schema, fake_questionnaire_store, routing_path)
    data = json.loads(json.dumps(output["data"]["answers"], for_json=True))

    answer_ids = {answer["answer_id"] for answer in data}
    assert "answer-one" not in answer_ids
Ejemplo n.º 5
0
def test_primary_person_not_in_payload_when_not_answered(
        fake_questionnaire_store):
    routing_path = [
        RoutingPath(
            [
                "list-collector", "next-interstitial",
                "another-list-collector-block"
            ],
            section_id="section-1",
        )
    ]

    answer_objects = [
        {
            "answer_id": "first-name",
            "value": "1",
            "list_item_id": "xJlKBy"
        },
        {
            "answer_id": "last-name",
            "value": "1",
            "list_item_id": "xJlKBy"
        },
        {
            "answer_id": "first-name",
            "value": "2",
            "list_item_id": "RfAGDc"
        },
        {
            "answer_id": "last-name",
            "value": "2",
            "list_item_id": "RfAGDc"
        },
        {
            "answer_id": "anyone-else",
            "value": "No"
        },
        {
            "answer_id": "another-anyone-else",
            "value": "No"
        },
        {
            "answer_id": "extraneous-answer",
            "value": "Bad",
            "list_item_id": "123"
        },
    ]

    answers = AnswerStore(answer_objects)

    list_store = ListStore(existing_items=[{
        "name": "people",
        "items": ["xJlKBy", "RfAGDc"]
    }])

    fake_questionnaire_store.answer_store = answers
    fake_questionnaire_store.list_store = list_store

    schema = load_schema("test_list_collector")

    output = convert_answers(schema, fake_questionnaire_store, routing_path)

    data_dict = json.loads(json.dumps(output["data"]["lists"], for_json=True))

    assert "primary_person" not in data_dict[0]
Ejemplo n.º 6
0
def test_list_item_conversion(fake_questionnaire_store):
    routing_path = [
        RoutingPath(
            [
                "list-collector",
                "next-interstitial",
                "another-list-collector-block",
                "group-summary",
            ],
            section_id="section-1",
        )
    ]

    answer_objects = [
        {
            "answer_id": "first-name",
            "value": "1",
            "list_item_id": "xJlKBy"
        },
        {
            "answer_id": "last-name",
            "value": "1",
            "list_item_id": "xJlKBy"
        },
        {
            "answer_id": "first-name",
            "value": "2",
            "list_item_id": "RfAGDc"
        },
        {
            "answer_id": "last-name",
            "value": "2",
            "list_item_id": "RfAGDc"
        },
        {
            "answer_id": "anyone-else",
            "value": "No"
        },
        {
            "answer_id": "another-anyone-else",
            "value": "No"
        },
        {
            "answer_id": "extraneous-answer",
            "value": "Bad",
            "list_item_id": "123"
        },
    ]

    answers = AnswerStore(answer_objects)

    list_store = ListStore(existing_items=[{
        "name": "people",
        "items": ["xJlKBy", "RfAGDc"]
    }])

    fake_questionnaire_store.answer_store = answers
    fake_questionnaire_store.list_store = list_store

    schema = load_schema("test_list_collector")

    output = convert_answers(schema, fake_questionnaire_store, routing_path)

    del answer_objects[-1]

    data_dict = json.loads(json.dumps(output["data"]["answers"],
                                      for_json=True))

    assert sorted(answer_objects, key=lambda x: x["answer_id"]) == sorted(
        data_dict, key=lambda x: x["answer_id"])
Ejemplo n.º 7
0
def test_primary_person_list_item_conversion(fake_questionnaire_store):
    routing_path = [
        RoutingPath(
            [
                "primary-person-list-collector", "list-collector",
                "group-summary"
            ],
            section_id="section-1",
        )
    ]

    answer_objects = [
        {
            "answer_id": "you-live-here",
            "value": "Yes"
        },
        {
            "answer_id": "first-name",
            "value": "1",
            "list_item_id": "xJlKBy"
        },
        {
            "answer_id": "last-name",
            "value": "1",
            "list_item_id": "xJlKBy"
        },
        {
            "answer_id": "first-name",
            "value": "2",
            "list_item_id": "RfAGDc"
        },
        {
            "answer_id": "last-name",
            "value": "2",
            "list_item_id": "RfAGDc"
        },
        {
            "answer_id": "anyone-else",
            "value": "No"
        },
    ]

    answers = AnswerStore(answer_objects)

    list_store = ListStore(existing_items=[{
        "name": "people",
        "items": ["xJlKBy", "RfAGDc"],
        "primary_person": "xJlKBy",
    }])

    fake_questionnaire_store.answer_store = answers
    fake_questionnaire_store.list_store = list_store

    schema = load_schema("test_list_collector_primary_person")

    output = convert_answers(schema, fake_questionnaire_store, routing_path)

    data_dict = json.loads(json.dumps(output["data"]["answers"],
                                      for_json=True))

    assert sorted(answer_objects, key=lambda x: x["answer_id"]) == sorted(
        data_dict, key=lambda x: x["answer_id"])