def test_get_context_no_list_items_survey_incomplete_individual_response_disabled( progress_store, answer_store, list_store, router): schema = load_schema_from_name("test_individual_response") hub_context = HubContext( language=None, progress_store=progress_store, list_store=list_store, schema=schema, answer_store=answer_store, metadata={}, ) assert not (hub_context.get_context( survey_complete=False, enabled_section_ids=router.enabled_section_ids) ["individual_response_enabled"])
def test_get_context_custom_content_complete( progress_store, answer_store, list_store, router ): schema = load_schema_from_name("test_hub_and_spoke_custom_content") hub_context = HubContext( language="en", progress_store=progress_store, list_store=list_store, schema=schema, answer_store=answer_store, metadata={}, response_metadata={}, ) expected_context = { "individual_response_enabled": False, "individual_response_url": None, "guidance": "Submission guidance", "rows": [], "submit_button": "Submission button", "title": "Submission title", "warning": "Submission warning", } assert expected_context == hub_context( survey_complete=True, enabled_section_ids=router.enabled_section_ids )
def test_get_completed_row_for_section(schema, progress_store, answer_store, list_store): expected = { "rowItems": [{ "rowTitle": "Breakfast", "rowTitleAttributes": { "data-qa": "hub-row-section-1-title" }, "attributes": { "data-qa": "hub-row-section-1-state" }, "icon": "check", "valueList": [{ "text": "Completed" }], "actions": [{ "text": "View answers", "ariaLabel": "View answers for Breakfast", "url": "http://some/url", "attributes": { "data-qa": "hub-row-section-1-link" }, }], }] } hub = HubContext( language=None, progress_store=progress_store, list_store=list_store, schema=schema, answer_store=answer_store, metadata={}, ) actual = hub.get_row_context_for_section( section_name="Breakfast", section_status=CompletionStatus.COMPLETED, section_url="http://some/url", row_id="section-1", ) assert expected == actual
def test_get_context(progress_store, answer_store, list_store, router): schema = load_schema_from_name("test_hub_and_spoke") hub = HubContext( language=None, progress_store=progress_store, list_store=list_store, schema=schema, answer_store=answer_store, metadata={}, ) expected_context = { "individual_response_enabled": False, "individual_response_url": None, "guidance": None, "rows": [], "submit_button": "Continue", "title": "Choose another section to complete", "warning": None, } assert expected_context == hub.get_context( survey_complete=False, enabled_section_ids=router.enabled_section_ids)
def get_questionnaire(schema, questionnaire_store): router = Router( schema, questionnaire_store.answer_store, questionnaire_store.list_store, questionnaire_store.progress_store, questionnaire_store.metadata, questionnaire_store.response_metadata, ) if not router.can_access_hub(): redirect_location_url = ( router.get_first_incomplete_location_in_questionnaire_url() ) return redirect(redirect_location_url) if request.method == "POST": if router.is_questionnaire_complete: submission_handler = SubmissionHandler( schema, questionnaire_store, router.full_routing_path() ) submission_handler.submit_questionnaire() return redirect(url_for("post_submission.get_thank_you")) return redirect(router.get_first_incomplete_location_in_questionnaire_url()) hub_context = HubContext( language=flask_babel.get_locale().language, schema=schema, answer_store=questionnaire_store.answer_store, list_store=questionnaire_store.list_store, progress_store=questionnaire_store.progress_store, metadata=questionnaire_store.metadata, response_metadata=questionnaire_store.response_metadata, ) context = hub_context( survey_complete=router.is_questionnaire_complete, enabled_section_ids=router.enabled_section_ids, ) return render_template( "hub", content=context, page_title=context["title"], )