def test_get_next_location_summary(self): schema = load_schema_from_params('0', 'star_wars') schema.answer_is_in_repeating_group = MagicMock(return_value=False) answer_1 = Answer( answer_id='choose-your-side-answer', value='Light Side' ) answer_2 = Answer( answer_id='light-side-pick-ship-answer', value='No', ) answers = AnswerStore() answers.add(answer_1) answers.add(answer_2) path_finder = PathFinder(schema, answer_store=answers, metadata={}, completed_blocks=[]) current_location = Location('star-wars', 0, 'star-wars-trivia-part-2') next_location = path_finder.get_next_location(current_location=current_location) expected_next_location = Location('star-wars', 0, 'star-wars-trivia-part-3') self.assertEqual(expected_next_location, next_location) current_location = expected_next_location next_location = path_finder.get_next_location(current_location=current_location) expected_next_location = Location('star-wars', 0, 'summary') self.assertEqual(expected_next_location, next_location)
def test_next_with_conditional_path(self): schema = load_schema_from_params('0', 'star_wars') expected_path = [ Location('star-wars', 0, 'choose-your-side-block'), Location('star-wars', 0, 'light-side-pick-character-ship'), Location('star-wars', 0, 'star-wars-trivia'), Location('star-wars', 0, 'star-wars-trivia-part-2'), Location('star-wars', 0, 'star-wars-trivia-part-3'), ] answer_1 = Answer( answer_id='choose-your-side-answer', value='Light Side' ) answer_2 = Answer( answer_id='light-side-pick-ship-answer', value='No' ) answers = AnswerStore() answers.add(answer_1) answers.add(answer_2) current_location = expected_path[1] expected_next_location = expected_path[2] completed_blocks = [ expected_path[0], expected_path[1] ] path_finder = PathFinder(schema, answer_store=answers, metadata={}, completed_blocks=completed_blocks) with patch('app.questionnaire.rules.evaluate_when_rules', side_effect=[True, False, True]): actual_next_block = path_finder.get_next_location(current_location=current_location) self.assertEqual(actual_next_block, expected_next_location) current_location = expected_path[2] expected_next_location = expected_path[3] path_finder.completed_blocks = [ expected_path[0], expected_path[1], expected_path[2] ] actual_next_block = path_finder.get_next_location(current_location=current_location) self.assertEqual(actual_next_block, expected_next_location)
def test_next_location_goto_summary(self): schema = load_schema_from_params('0', 'star_wars') schema.answer_is_in_repeating_group = MagicMock(return_value=False) expected_path = [ Location('star-wars', 0, 'introduction'), Location('star-wars', 0, 'choose-your-side-block'), Location('star-wars', 0, 'summary'), ] answer = Answer( group_instance=0, answer_id='choose-your-side-answer', value='I prefer Star Trek', ) answers = AnswerStore() answers.add(answer) path_finder = PathFinder(schema, answer_store=answers, metadata={}, completed_blocks=[]) current_location = expected_path[1] expected_next_location = expected_path[2] next_location = path_finder.get_next_location(current_location=current_location) self.assertEqual(next_location, expected_next_location)
def test_next_location_empty_routing_rules(self): schema = load_schema_from_params('test', 'checkbox') schema.answer_is_in_repeating_group = MagicMock(return_value=False) expected_path = [ Location('checkboxes', 0, 'mandatory-checkbox'), Location('checkboxes', 0, 'non-mandatory-checkbox'), Location('checkboxes', 0, 'summary') ] answer_1 = Answer( answer_id='mandatory-checkbox-answer', value='Cheese', ) answer_2 = Answer( answer_id='non-mandatory-checkbox-answer', value='deep pan', ) answers = AnswerStore() answers.add(answer_1) answers.add(answer_2) path_finder = PathFinder(schema, answer_store=answers, metadata={}, completed_blocks=[]) current_location = expected_path[0] expected_next_location = expected_path[1] next_location = path_finder.get_next_location(current_location=current_location) self.assertEqual(next_location, expected_next_location)
def test_next_location_empty_routing_rules(self): survey = load_schema_file("test_checkbox.json") expected_path = [ Location("checkboxes", 0, 'introduction'), Location("checkboxes", 0, 'mandatory-checkbox'), Location("checkboxes", 0, 'non-mandatory-checkbox'), Location("checkboxes", 0, 'summary') ] answer_1 = Answer( group_id="checkboxes", block_id="mandatory-checkbox", answer_id="mandatory-checkbox-answer", value="Cheese", ) answer_2 = Answer( group_id="checkboxes", block_id="non-mandatory-checkbox", answer_id="non-mandatory-checkbox-answer", value="deep pan", ) answers = AnswerStore() answers.add(answer_1) answers.add(answer_2) path_finder = PathFinder(survey, answer_store=answers) current_location = expected_path[1] expected_next_location = expected_path[2] next_location = path_finder.get_next_location(current_location=current_location) self.assertEqual(next_location, expected_next_location)
def test_next_location_goto_summary(self): survey = load_schema_file("0_star_wars.json") expected_path = [ Location("star-wars", 0, 'introduction'), Location("star-wars", 0, 'choose-your-side-block'), Location("star-wars", 0, 'summary'), ] answer = Answer( group_id="star-wars", group_instance=0, block_id="choose-your-side-block", answer_id="choose-your-side-answer", value="I prefer Star Trek", ) answers = AnswerStore() answers.add(answer) path_finder = PathFinder(survey, answer_store=answers) current_location = expected_path[1] expected_next_location = expected_path[2] next_location = path_finder.get_next_location(current_location=current_location) self.assertEqual(next_location, expected_next_location)
def post_block(eq_id, form_type, collection_id, group_id, group_instance, block_id): 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(group_id, group_instance, block_id) if 'action[save_sign_out]' in request.form: return _save_sign_out(collection_id, eq_id, form_type, q_manager, this_location) valid_location = this_location in path_finder.get_routing_path(group_id, group_instance) valid_data = q_manager.validate(this_location, request.form) if not valid_location or not valid_data: current_location = Location(group_id, group_instance, block_id) _render_schema(current_location) return _build_template(current_location, q_manager.block_state, template='questionnaire') else: q_manager.update_questionnaire_store(this_location) next_location = path_finder.get_next_location(current_location=this_location) if next_location is None: raise NotFound metadata = get_metadata(current_user) return redirect(next_location.url(metadata))
def post_household_composition(eq_id, form_type, collection_id, group_id): questionnaire_manager = get_questionnaire_manager(g.schema, g.schema_json) answer_store = get_answer_store(current_user) this_location = Location(group_id, group_instance=0, block_id='household-composition') if 'action[save_continue]' in request.form: _remove_repeating_on_household_answers(answer_store, group_id) valid = questionnaire_manager.process_incoming_answers(this_location, post_data=request.form) if 'action[add_answer]' in request.form: questionnaire_manager.add_answer(this_location, answer_store, question_id='household-composition-question') return get_block(eq_id, form_type, collection_id, group_id, group_instance=0, block_id='household-composition') elif 'action[remove_answer]' in request.form: index_to_remove = int(request.form.get('action[remove_answer]')) questionnaire_manager.remove_answer(this_location, answer_store, index_to_remove) return get_block(eq_id, form_type, collection_id, group_id, group_instance=0, block_id='household-composition') elif 'action[save_sign_out]' in request.form: return _save_sign_out(collection_id, eq_id, form_type, questionnaire_manager, this_location) if not valid: _render_schema(this_location) return _build_template(current_location=this_location, context=questionnaire_manager.block_state, template='questionnaire') path_finder = PathFinder(g.schema_json, get_answer_store(current_user), get_metadata(current_user)) next_location = path_finder.get_next_location(current_location=this_location) metadata = get_metadata(current_user) return redirect(next_location.url(metadata))
def test_next_location_goto_summary(self): survey = load_schema_file("0_star_wars.json") expected_path = [ Location("14ba4707-321d-441d-8d21-b8367366e766", 0, 'introduction'), Location("14ba4707-321d-441d-8d21-b8367366e766", 0, 'choose-your-side-block'), Location("14ba4707-321d-441d-8d21-b8367366e766", 0, 'summary'), ] answer = Answer( group_id="14ba4707-321d-441d-8d21-b8367366e766", group_instance=0, block_id="choose-your-side-block", answer_id="ca3ce3a3-ae44-4e30-8f85-5b6a7a2fb23c", value="I prefer Star Trek", ) answers = AnswerStore() answers.add(answer) path_finder = PathFinder(survey, answer_store=answers) current_location = expected_path[1] expected_next_location = expected_path[2] next_location = path_finder.get_next_location( current_location=current_location) self.assertEqual(next_location, expected_next_location)
def test_next_with_conditional_path(self): survey = load_schema_file("0_star_wars.json") expected_path = [ Location("14ba4707-321d-441d-8d21-b8367366e766", 0, "choose-your-side-block"), Location("14ba4707-321d-441d-8d21-b8367366e766", 0, "96682325-47ab-41e4-a56e-8315a19ffe2a"), Location("14ba4707-321d-441d-8d21-b8367366e766", 0, "cd3b74d1-b687-4051-9634-a8f9ce10a27d"), Location("14ba4707-321d-441d-8d21-b8367366e766", 0, "an3b74d1-b687-4051-9634-a8f9ce10ard"), Location("14ba4707-321d-441d-8d21-b8367366e766", 0, "846f8514-fed2-4bd7-8fb2-4b5fcb1622b1"), ] answer_1 = Answer(group_id="14ba4707-321d-441d-8d21-b8367366e766", block_id="choose-your-side-block", answer_id="ca3ce3a3-ae44-4e30-8f85-5b6a7a2fb23c", value="Light Side") answer_2 = Answer(group_id="14ba4707-321d-441d-8d21-b8367366e766", block_id="96682325-47ab-41e4-a56e-8315a19ffe2a", answer_id="2e0989b8-5185-4ba6-b73f-c126e3a06ba7", value="No") answers = AnswerStore() answers.add(answer_1) answers.add(answer_2) current_location = expected_path[1] expected_next_location = expected_path[2] path_finder = PathFinder(survey, answer_store=answers) actual_next_block = path_finder.get_next_location( current_location=current_location) self.assertEqual(actual_next_block, expected_next_location) current_location = expected_path[2] expected_next_location = expected_path[3] actual_next_block = path_finder.get_next_location( current_location=current_location) self.assertEqual(actual_next_block, expected_next_location)
def test_next_with_conditional_path(self): survey = load_schema_file("0_star_wars.json") expected_path = [ Location("star-wars", 0, "choose-your-side-block"), Location("star-wars", 0, "light-side-pick-character-ship"), Location("star-wars", 0, "star-wars-trivia"), Location("star-wars", 0, "star-wars-trivia-part-2"), Location("star-wars", 0, "star-wars-trivia-part-3"), ] answer_1 = Answer( group_id="star-wars", block_id="choose-your-side-block", answer_id="choose-your-side-answer", value="Light Side" ) answer_2 = Answer( group_id="star-wars", block_id="light-side-pick-character-ship", answer_id="light-side-pick-ship-answer", value="No" ) answers = AnswerStore() answers.add(answer_1) answers.add(answer_2) current_location = expected_path[1] expected_next_location = expected_path[2] path_finder = PathFinder(survey, answer_store=answers) actual_next_block = path_finder.get_next_location(current_location=current_location) self.assertEqual(actual_next_block, expected_next_location) current_location = expected_path[2] expected_next_location = expected_path[3] actual_next_block = path_finder.get_next_location(current_location=current_location) self.assertEqual(actual_next_block, expected_next_location)
def test_get_next_location_introduction(self): survey = load_schema_file("0_star_wars.json") path_finder = PathFinder(survey) introduction = Location('star-wars', 0, 'introduction') next_location = path_finder.get_next_location(current_location=introduction) self.assertEqual('choose-your-side-block', next_location.block_id)
def test_get_next_location_introduction(self): schema = load_schema_from_params('0', 'star_wars') schema.answer_is_in_repeating_group = MagicMock(return_value=False) introduction = Location('star-wars', 0, 'introduction') path_finder = PathFinder(schema, AnswerStore(), {}, [introduction]) next_location = path_finder.get_next_location(current_location=introduction) self.assertEqual('choose-your-side-block', next_location.block_id)
def test_get_next_location_summary(self): survey = load_schema_file("0_star_wars.json") answer_1 = Answer(group_id="14ba4707-321d-441d-8d21-b8367366e766", block_id="choose-your-side-block", answer_id="ca3ce3a3-ae44-4e30-8f85-5b6a7a2fb23c", value="Light Side") answer_2 = Answer( group_id="14ba4707-321d-441d-8d21-b8367366e766", block_id="96682325-47ab-41e4-a56e-8315a19ffe2a", answer_id="2e0989b8-5185-4ba6-b73f-c126e3a06ba7", value="No", ) answers = AnswerStore() answers.add(answer_1) answers.add(answer_2) path_finder = PathFinder(survey, answer_store=answers) current_location = Location('14ba4707-321d-441d-8d21-b8367366e766', 0, 'an3b74d1-b687-4051-9634-a8f9ce10ard') next_location = path_finder.get_next_location( current_location=current_location) expected_next_location = Location( "14ba4707-321d-441d-8d21-b8367366e766", 0, '846f8514-fed2-4bd7-8fb2-4b5fcb1622b1') self.assertEqual(expected_next_location, next_location) current_location = expected_next_location next_location = path_finder.get_next_location( current_location=current_location) expected_next_location = Location( "14ba4707-321d-441d-8d21-b8367366e766", 0, 'summary') self.assertEqual(expected_next_location, next_location)
def post_household_composition(eq_id, form_type, collection_id, group_id): # pylint: disable=too-many-locals answer_store = get_answer_store(current_user) if _household_answers_changed(answer_store): _remove_repeating_on_household_answers(answer_store, group_id) error_messages = SchemaHelper.get_messages(g.schema_json) disable_mandatory = any(x in request.form for x in [ 'action[add_answer]', 'action[remove_answer]', 'action[save_sign_out]' ]) current_location = Location(group_id, 0, 'household-composition') block = _render_schema(current_location) form, _ = post_form_for_location(block, current_location, answer_store, request.form, error_messages, disable_mandatory=disable_mandatory) if 'action[add_answer]' in request.form: form.household.append_entry() elif 'action[remove_answer]' in request.form: index_to_remove = int(request.form.get('action[remove_answer]')) form.remove_person(index_to_remove) elif 'action[save_sign_out]' in request.form: response = _save_sign_out(collection_id, eq_id, form_type, current_location, form) remove_empty_household_members_from_answer_store( answer_store, group_id) return response if _is_invalid_form( form ) or 'action[add_answer]' in request.form or 'action[remove_answer]' in request.form: context = {'form': form, 'block': block} return _build_template(current_location, context, template='questionnaire') else: questionnaire_store = get_questionnaire_store(current_user.user_id, current_user.user_ik) update_questionnaire_store_with_answer_data( questionnaire_store, current_location, form.serialise(current_location)) metadata = get_metadata(current_user) path_finder = PathFinder(g.schema_json, get_answer_store(current_user), metadata) next_location = path_finder.get_next_location( current_location=current_location) return redirect(next_location.url(metadata))
def test_get_next_location_should_not_skip_when_no_answers(self): # Given survey = load_schema_file('test_skip_condition_group.json') current_location = Location('do-you-want-to-skip-group', 0, 'do-you-want-to-skip') answer_store = AnswerStore() # When path_finder = PathFinder(survey, answer_store=answer_store) # Then expected_location = Location('should-skip-group', 0, 'should-skip') self.assertEqual(path_finder.get_next_location(current_location=current_location), expected_location)
def test_routing_backwards_continues_to_summary_when_complete(self): survey = load_schema_file("test_household_question.json") expected_path = [ Location('multiple-questions-group', 0, 'introduction'), Location('multiple-questions-group', 0, 'household-composition'), Location('multiple-questions-group', 0, 'household-summary'), Location('multiple-questions-group', 0, 'summary'), ] current_location = expected_path[2] expected_next_location = expected_path[3] answers = AnswerStore() answer_1 = Answer( group_id="multiple-questions-group", group_instance=0, block_id="household-composition", answer_id="household-full-name", answer_instance=0, value="Joe Bloggs" ) answer_2 = Answer( group_id="multiple-questions-group", group_instance=0, block_id="household-composition", answer_id="household-full-name", answer_instance=1, value="Sophie Bloggs" ) answer_3 = Answer( group_id="multiple-questions-group", group_instance=0, block_id="household-summary", answer_id="household-composition-add-another", answer_instance=0, value="Yes" ) answers.add(answer_1) answers.add(answer_2) answers.add(answer_3) path_finder = PathFinder(survey, answer_store=answers) self.assertEqual(expected_next_location, path_finder.get_next_location(current_location=current_location))
def test_get_next_location_confirmation(self): answer = Answer( answer_id="character-answer", value="Orson Krennic", ) answer_store = AnswerStore() answer_store.add(answer) survey = load_schema_file("0_rogue_one.json") navigator = PathFinder(survey, answer_store) next_location = navigator.get_next_location( Location('rogue-one', 0, 'film-takings')) self.assertEqual('summary', next_location.block_id)
def test_get_next_location_confirmation(self): answer = Answer( answer_id="ca3ce3a3-ae44-4e30-8f85-5b6a7a2fb23c", value="Orson Krennic", ) answer_store = AnswerStore() answer_store.add(answer) survey = load_schema_file("0_rogue_one.json") navigator = PathFinder(survey, answer_store) next_location = navigator.get_next_location( SchemaHelper.get_last_location(survey)) self.assertEqual('summary', next_location.block_id)
def test_get_next_location_summary(self): survey = load_schema_file("0_star_wars.json") answer_1 = Answer( group_id="star-wars", block_id="choose-your-side-block", answer_id="choose-your-side-answer", value="Light Side" ) answer_2 = Answer( group_id="star-wars", block_id="light-side-pick-character-ship", answer_id="light-side-pick-ship-answer", value="No", ) answers = AnswerStore() answers.add(answer_1) answers.add(answer_2) path_finder = PathFinder(survey, answer_store=answers) current_location = Location('star-wars', 0, 'star-wars-trivia-part-2') next_location = path_finder.get_next_location(current_location=current_location) expected_next_location = Location("star-wars", 0, 'star-wars-trivia-part-3') self.assertEqual(expected_next_location, next_location) current_location = expected_next_location next_location = path_finder.get_next_location(current_location=current_location) expected_next_location = Location("star-wars", 0, 'summary') self.assertEqual(expected_next_location, next_location)
def test_get_next_location_should_skip_group(self): # Given survey = load_schema_file('test_skip_condition_group.json') current_location = Location('do-you-want-to-skip-group', 0, 'do-you-want-to-skip') answer_store = AnswerStore() answer_store.add(Answer(group_id='do-you-want-to-skip-group', block_id='do-you-want-to-skip', answer_id='do-you-want-to-skip-answer', value='Yes')) # When path_finder = PathFinder(survey, answer_store=answer_store) # Then expected_next_location = Location('last-group', 0, 'last-group-block') self.assertEqual(path_finder.get_next_location(current_location=current_location), expected_next_location)
def test_next_block(self): survey = load_schema_file("1_0102.json") current_location = Location(block_id="total-retail-turnover", group_id="rsi", group_instance=0) next_location = Location(block_id="internet-sales", group_id="rsi", group_instance=0) path_finder = PathFinder(survey) self.assertEqual( path_finder.get_next_location(current_location=current_location), next_location)
def post_block(eq_id, form_type, collection_id, group_id, group_instance, block_id): # pylint: disable=too-many-locals current_location = Location(group_id, group_instance, block_id) metadata = get_metadata(current_user) answer_store = get_answer_store(current_user) path_finder = PathFinder(g.schema_json, answer_store, metadata) valid_group = group_id in SchemaHelper.get_group_ids(g.schema_json) full_routing_path = path_finder.get_routing_path() is_valid_location = valid_group and current_location in path_finder.get_routing_path( group_id, group_instance) if not is_valid_location: latest_location = path_finder.get_latest_location( get_completed_blocks(current_user), routing_path=full_routing_path) return _redirect_to_location(collection_id, eq_id, form_type, latest_location) error_messages = SchemaHelper.get_messages(g.schema_json) block = _render_schema(current_location) disable_mandatory = 'action[save_sign_out]' in request.form form, _ = post_form_for_location(block, current_location, answer_store, request.form, error_messages, disable_mandatory=disable_mandatory) if 'action[save_sign_out]' in request.form: return _save_sign_out(collection_id, eq_id, form_type, current_location, form) elif _is_invalid_form(form): context = {'form': form, 'block': block} return _build_template(current_location, context, template=block['type'], routing_path=full_routing_path) else: _update_questionnaire_store(current_location, form) next_location = path_finder.get_next_location( current_location=current_location) if next_location is None and block['type'] in [ "Summary", "Confirmation" ]: return submit_answers(eq_id, form_type, collection_id, metadata, answer_store) return redirect(next_location.url(metadata))
def test_get_next_location_should_not_skip_group(self): # Given schema = load_schema_from_params('test', 'skip_condition_group') current_location = Location('do-you-want-to-skip-group', 0, 'do-you-want-to-skip') answer_store = AnswerStore() answer_store.add(Answer(answer_id='do-you-want-to-skip-answer', value='No')) # When path_finder = PathFinder(schema, answer_store=answer_store, metadata={}, completed_blocks=[]) # Then expected_location = Location('should-skip-group', 0, 'should-skip') with patch('app.questionnaire.path_finder.evaluate_skip_conditions', return_value=False): self.assertEqual(path_finder.get_next_location(current_location=current_location), expected_location)
def test_get_next_location_confirmation(self): answer = Answer( answer_id='character-answer', value='Orson Krennic', ) answer_store = AnswerStore() answer_store.add(answer) schema = load_schema_from_params('0', 'rogue_one') navigator = PathFinder(schema, answer_store, {}, []) with patch('app.questionnaire.rules.evaluate_when_rules', return_value=True): next_location = navigator.get_next_location( Location('rogue-one', 0, 'film-takings')) self.assertEqual('summary', next_location.block_id)
def test_next_with_conditional_path_when_value_not_in_metadata(self): schema = load_schema_from_params('test', 'metadata_routing') expected_path = [ Location('group1', 0, 'block1'), Location('group1', 0, 'block2'), ] current_location = expected_path[0] expected_next_location = expected_path[1] metadata = {} path_finder = PathFinder(schema, AnswerStore(), metadata=metadata, completed_blocks=[]) self.assertEqual(expected_next_location, path_finder.get_next_location(current_location=current_location))
def test_next_block(self): schema = load_schema_from_params('test', '0102') current_location = Location( block_id='total-retail-turnover', group_id='rsi', group_instance=0 ) next_location = Location( block_id='internet-sales', group_id='rsi', group_instance=0 ) path_finder = PathFinder(schema, AnswerStore(), metadata={}, completed_blocks=[]) self.assertEqual(path_finder.get_next_location(current_location=current_location), next_location)
def test_routing_backwards_continues_to_summary_when_complete(self): schema = load_schema_from_params('test', 'household_question') expected_path = [ Location('multiple-questions-group', 0, 'introduction'), Location('multiple-questions-group', 0, 'household-composition'), Location('multiple-questions-group', 0, 'household-summary'), Location('multiple-questions-group', 0, 'summary'), ] current_location = expected_path[2] expected_next_location = expected_path[3] answers = AnswerStore() answer_1 = Answer( group_instance=0, answer_id='household-full-name', answer_instance=0, value='Joe Bloggs' ) answer_2 = Answer( group_instance=0, answer_id='household-full-name', answer_instance=1, value='Sophie Bloggs' ) answer_3 = Answer( group_instance=0, answer_id='household-composition-add-another', answer_instance=0, value='Yes' ) answers.add(answer_1) answers.add(answer_2) answers.add(answer_3) path_finder = PathFinder(schema, answer_store=answers, metadata={}, completed_blocks=[]) with patch('app.questionnaire.path_finder.evaluate_goto', side_effect=[False, True, False, True]): self.assertEqual(expected_next_location, path_finder.get_next_location(current_location=current_location))
def post_household_composition(eq_id, form_type, collection_id, group_id): path_finder = PathFinder(g.schema_json, get_answer_store(current_user), get_metadata(current_user)) answer_store = get_answer_store(current_user) questionnaire_store = get_questionnaire_store(current_user.user_id, current_user.user_ik) current_location = Location(group_id, 0, 'household-composition') block = _render_schema(current_location) if _household_answers_changed(answer_store): _remove_repeating_on_household_answers(answer_store, group_id) error_messages = SchemaHelper.get_messages(g.schema_json) if any(x in request.form for x in ['action[add_answer]', 'action[remove_answer]', 'action[save_sign_out]']): disable_mandatory = True else: disable_mandatory = False form, _ = post_form_for_location(block, current_location, answer_store, request.form, error_messages, disable_mandatory=disable_mandatory) if 'action[add_answer]' in request.form: form.household.append_entry() elif 'action[remove_answer]' in request.form: index_to_remove = int(request.form.get('action[remove_answer]')) form.remove_person(index_to_remove) elif 'action[save_sign_out]' in request.form: return _save_sign_out(collection_id, eq_id, form_type, current_location, form) if not form.validate() or 'action[add_answer]' in request.form or 'action[remove_answer]' in request.form: return _render_template({ 'form': form, 'block': block, }, current_location.block_id, current_location=current_location, template='questionnaire') update_questionnaire_store_with_answer_data(questionnaire_store, current_location, form.serialise(current_location)) next_location = path_finder.get_next_location(current_location=current_location) metadata = get_metadata(current_user) return redirect(next_location.url(metadata))
def test_next_with_conditional_path_when_value_not_in_metadata(self): survey = load_schema_file("test_metadata_routing.json") expected_path = [ Location("group1", 0, "block1"), Location("group1", 0, "block2"), ] current_location = expected_path[0] expected_next_location = expected_path[1] metadata = {"variant_flags": {}} path_finder = PathFinder(survey, metadata=metadata) self.assertEqual( expected_next_location, path_finder.get_next_location(current_location=current_location))