Beispiel #1
0
    def test_introduction_not_in_path_when_not_in_schema(self):
        survey = load_schema_file("census_individual.json")

        path_finder = PathFinder(survey)

        blocks = [b.block_id for b in path_finder.get_location_path()]

        self.assertNotIn('introduction', blocks)
Beispiel #2
0
    def validate_all_answers(self):

        navigator = PathFinder(self._json, get_answer_store(current_user), get_metadata(current_user))

        for location in navigator.get_location_path():
            answers = get_answers(current_user)
            is_valid = self.validate(location, answers)

            if not is_valid:
                logger.debug("Failed validation with current location %s", str(location))
                return False, location

        return True, None
def validate_all_answers(answer_store, metadata):

    path_finder = PathFinder(g.schema_json, answer_store, metadata)
    error_messages = SchemaHelper.get_messages(g.schema_json)

    for location in path_finder.get_location_path():
        if not location.is_interstitial():
            block_json = _render_schema(location)
            form, _ = get_form_for_location(block_json, location, answer_store, error_messages)

            if not form.validate():
                logger.debug("Failed validation", location=str(location))
                return False, location

    return True, None
Beispiel #4
0
    def test_interstitial_post_blocks(self):
        survey = load_schema_file("0_star_wars.json")

        answer = Answer(group_id="14ba4707-321d-441d-8d21-b8367366e766",
                        block_id="choose-your-side-block",
                        answer_id="ca3ce3a3-ae44-4e30-8f85-5b6a7a2fb23c",
                        value="Light Side")

        answers = AnswerStore()
        answers.add(answer)

        path_finder = PathFinder(survey, answer_store=answers)

        self.assertFalse(
            Location("14ba4707-321d-441d-8d21-b8367366e766", 0, 'summary') in
            path_finder.get_location_path())
Beispiel #5
0
    def test_repeating_groups_conditional_location_path(self):
        survey = load_schema_file(
            "test_repeating_and_conditional_routing.json")

        expected_path = [
            Location("repeat-value-group", 0, "introduction"),
            Location("repeat-value-group", 0, "no-of-repeats"),
            Location("repeated-group", 0, "repeated-block"),
            Location("repeated-group", 0, "age-block"),
            Location("repeated-group", 0, "shoe-size-block"),
            Location("repeated-group", 1, "repeated-block"),
            Location("repeated-group", 1, "shoe-size-block"),
            Location("repeated-group", 0, "summary"),
            Location("repeated-group", 0, "thank-you"),
        ]

        answer_1 = Answer(group_id="repeat-value-group",
                          block_id="no-of-repeats",
                          answer_id="no-of-repeats-answer",
                          value="2")

        answer_2 = Answer(group_id="repeated-group",
                          group_instance=0,
                          block_id="repeated-block",
                          answer_id="conditional-answer",
                          value="Age and Shoe Size")

        answer_3 = Answer(group_id="repeated-group",
                          group_instance=1,
                          block_id="repeated-block",
                          answer_id="conditional-answer",
                          value="Shoe Size Only")

        answers = AnswerStore()
        answers.add(answer_1)
        answers.add(answer_2)
        answers.add(answer_3)

        path_finder = PathFinder(survey, answer_store=answers)

        self.assertEqual(expected_path, path_finder.get_location_path())
Beispiel #6
0
def post_interstitial(eq_id, form_type, collection_id, block_id):  # pylint: disable=unused-argument
    path_finder = PathFinder(g.schema_json, get_answer_store(current_user), get_metadata(current_user))
    q_manager = get_questionnaire_manager(g.schema, g.schema_json)

    this_location = Location(SchemaHelper.get_first_group_id(g.schema_json), group_instance=0, block_id=block_id)

    q_manager.update_questionnaire_store(this_location)

    # Don't care if data is valid because there isn't any for interstitial
    if this_location not in path_finder.get_location_path():
        _render_schema(this_location)
        return _build_template(current_location=this_location, context=q_manager.block_state, template='questionnaire')

    next_location = path_finder.get_next_location(current_location=this_location)

    if next_location is None:
        raise NotFound

    metadata = get_metadata(current_user)
    logger.info("Redirecting user to next location %s with tx_id=%s", str(next_location), metadata["tx_id"])
    return redirect(next_location.url(metadata))
def post_interstitial(eq_id, form_type, collection_id, block_id):  # pylint: disable=unused-argument
    path_finder = PathFinder(g.schema_json, get_answer_store(current_user), get_metadata(current_user))

    current_location = Location(SchemaHelper.get_first_group_id(g.schema_json), 0, block_id)

    valid_location = current_location in path_finder.get_location_path()
    questionnaire_store = get_questionnaire_store(current_user.user_id, current_user.user_ik)
    update_questionnaire_store_with_form_data(questionnaire_store, current_location, request.form.to_dict())

    # Don't care if data is valid because there isn't any for interstitial
    if not valid_location:
        block = _render_schema(current_location)
        return _build_template(current_location=current_location, context={"block": block}, template='questionnaire')

    next_location = path_finder.get_next_location(current_location=current_location)

    if next_location is None:
        raise NotFound

    metadata = get_metadata(current_user)
    next_location_url = next_location.url(metadata)
    logger.debug("redirecting", url=next_location_url)
    return redirect(next_location_url)
Beispiel #8
0
    def test_excessive_repeating_groups_conditional_location_path(self):
        survey = load_schema_file(
            "test_repeating_and_conditional_routing.json")

        answers = AnswerStore()

        answers.add(
            Answer(group_id="repeat-value-group",
                   block_id="no-of-repeats",
                   answer_id="no-of-repeats-answer",
                   value="10000"))

        for i in range(50):
            answers.add(
                Answer(group_id="repeated-group",
                       group_instance=i,
                       block_id="repeated-block",
                       answer_id="conditional-answer",
                       value="Shoe Size Only"))

        path_finder = PathFinder(survey, answer_store=answers)

        self.assertEqual("thank-you",
                         path_finder.get_location_path().pop().block_id)