def test_is_not_valid_location(self): schema = load_schema_from_params('test', 'is_skipping_to_end') current_location = Location('not-in-path', 0, 'not-in-path') routing_path = [ Location('test-skipping-group', 0, 'test-skipping-forced'), Location('test-skipping-section-summary-group', 0, 'test-skipping-section-summary'), Location('summary-group', 0, 'summary') ] completed_blocks = [ Location('test-skipping-group', 0, 'test-skipping-forced') ] completeness = Completeness(schema, answer_store=MagicMock(), completed_blocks=completed_blocks, routing_path=routing_path, metadata={}) router = Router(schema, routing_path, completeness, current_location) self.assertFalse(router.can_access_location()) router = Router(schema, routing_path, completeness) self.assertFalse(router.can_access_location()) # Currently, section summary is not added to completed_blocks without POST, ie when using nav bar. self.assertEqual(routing_path[2], router.get_next_location())
def get_block( routing_path, schema, metadata, answer_store, eq_id, form_type, collection_id, group_id, # pylint: disable=too-many-locals group_instance, block_id): current_location = Location(group_id, group_instance, block_id) completeness = get_completeness(current_user) router = Router(schema, routing_path, completeness, current_location) if not router.can_access_location(): next_location = router.get_next_location() return _redirect_to_location(collection_id, eq_id, form_type, next_location) block = _get_block_json(current_location, schema, answer_store, metadata) context = _get_context(routing_path, block, current_location, schema) return _render_page(block['type'], context, current_location, schema, answer_store, metadata, routing_path)
def test_section_summary_accessible_when_section_complete(self): schema = load_schema_from_params('test', 'is_skipping_to_end') current_location = Location('test-skipping-section-summary-group-2', 0, 'test-skipping-section-summary-2') routing_path = [ Location('test-skipping-group', 0, 'test-skipping-forced'), Location('test-skipping-group', 0, 'test-skipping-optional'), Location('test-skipping-section-summary-group', 0, 'test-skipping-section-summary'), Location('test-skipping-group-2', 0, 'test-skipping-forced-2'), Location('test-skipping-group-2', 0, 'test-skipping-optional-2'), Location('test-skipping-section-summary-group-2', 0, 'test-skipping-section-summary-2'), Location('summary-group', 0, 'summary') ] completed_blocks = [ Location('test-skipping-group', 0, 'test-skipping-forced'), Location('test-skipping-group-2', 0, 'test-skipping-forced-2'), Location('test-skipping-group-2', 0, 'test-skipping-optional-2'), Location('test-skipping-section-summary-group-2', 0, 'test-skipping-section-summary-2') ] completeness = Completeness(schema, answer_store=MagicMock(), completed_blocks=completed_blocks, routing_path=routing_path, metadata={}) router = Router(schema, routing_path, completeness, current_location) self.assertTrue(router.can_access_location()) self.assertEqual(routing_path[1], router.get_next_location())
def post_block( routing_path, schema, metadata, collection_metadata, answer_store, eq_id, form_type, collection_id, group_id, # pylint: disable=too-many-locals group_instance, block_id): current_location = Location(group_id, group_instance, block_id) completeness = get_completeness(current_user) router = Router(schema, routing_path, completeness, current_location) if not router.can_access_location(): next_location = router.get_next_location() return _redirect_to_location(collection_id, eq_id, form_type, next_location) block = _get_block_json(current_location, schema, answer_store, metadata) schema_context = _get_schema_context(routing_path, current_location, metadata, collection_metadata, answer_store, schema) rendered_block = renderer.render(block, **schema_context) form = _generate_wtf_form(request.form, rendered_block, current_location, schema) if 'action[save_sign_out]' in request.form: return _save_sign_out(routing_path, current_location, form, schema, answer_store, metadata) if form.validate(): _set_started_at_metadata_if_required(form, collection_metadata) _update_questionnaire_store(current_location, form, schema) next_location = path_finder.get_next_location( current_location=current_location) if _is_end_of_questionnaire(block, next_location): return submit_answers(routing_path, eq_id, form_type, schema) return redirect(_next_location_url(next_location)) context = build_view_context(block['type'], metadata, schema, answer_store, schema_context, rendered_block, current_location, form) return _render_page(block['type'], context, current_location, schema, answer_store, metadata, routing_path)
def login(): """ Initial url processing - expects a token parameter and then will authenticate this token. Once authenticated it will be placed in the users session :return: a 302 redirect to the next location for the user """ # logging in again clears any session state if cookie_session: cookie_session.clear() decrypted_token = decrypt_token(request.args.get('token')) validate_jti(decrypted_token) claims = parse_runner_claims(decrypted_token) g.schema = load_schema_from_metadata(claims) schema_metadata = g.schema.json['metadata'] validate_metadata(claims, schema_metadata) eq_id = claims['eq_id'] form_type = claims['form_type'] tx_id = claims['tx_id'] ru_ref = claims['ru_ref'] logger.bind(eq_id=eq_id, form_type=form_type, tx_id=tx_id, ru_ref=ru_ref) logger.info('decrypted token and parsed metadata') store_session(claims) cookie_session['theme'] = g.schema.json['theme'] cookie_session['survey_title'] = g.schema.json['title'] cookie_session['expires_in'] = get_session_timeout_in_seconds(g.schema) if claims.get('account_service_url'): cookie_session['account_service_url'] = claims.get( 'account_service_url') if claims.get('account_service_log_out_url'): cookie_session['account_service_log_out_url'] = claims.get( 'account_service_log_out_url') routing_path = path_finder.get_full_routing_path() completeness = get_completeness(current_user) router = Router(g.schema, routing_path, completeness) next_location = router.get_next_location() return redirect(next_location.url(claims))
def get_thank_you(schema, metadata, eq_id, form_type): session_data = get_session_store().session_data completeness = get_completeness(current_user) if session_data.submitted_time: metadata_context = build_metadata_context_for_survey_completed( session_data) view_submission_url = None view_submission_duration = 0 if _is_submission_viewable(schema.json, session_data.submitted_time): view_submission_url = url_for('.get_view_submission', eq_id=eq_id, form_type=form_type) view_submission_duration = humanize.naturaldelta( timedelta(seconds=schema.json['view_submitted_response'] ['duration'])) cookie_message = request.cookies.get('ons_cookie_message_displayed') allow_analytics = analytics_allowed(request) return render_theme_template( schema.json['theme'], template_name='thank-you.html', metadata=metadata_context, analytics_gtm_id=current_app.config['EQ_GTM_ID'], analytics_gtm_env_id=current_app.config['EQ_GTM_ENV_ID'], survey_id=schema.json['survey_id'], survey_title=TemplateRenderer.safe_content(schema.json['title']), is_view_submitted_response_enabled= is_view_submitted_response_enabled(schema.json), view_submission_url=view_submission_url, account_service_url=cookie_session.get('account_service_url'), account_service_log_out_url=cookie_session.get( 'account_service_log_out_url'), view_submission_duration=view_submission_duration, cookie_message=cookie_message, allow_analytics=allow_analytics) routing_path = path_finder.get_full_routing_path() router = Router(schema, routing_path, completeness) next_location = router.get_next_location() return _redirect_to_location(metadata['collection_exercise_sid'], metadata.get('eq_id'), metadata.get('form_type'), next_location)
def test_get_next_location_no_completed_blocks(self): schema = load_schema_from_params('test', 'is_skipping_to_end') current_location = Location('test-skipping-group', 0, 'test-skipping-forced') routing_path = [ Location('test-skipping-group', 0, 'test-skipping-forced') ] completeness = Completeness(schema, answer_store=MagicMock(), completed_blocks=[], routing_path=routing_path, metadata={}) router = Router(schema, routing_path, completeness, current_location) self.assertEqual(routing_path[0], router.get_next_location())
def get_thank_you(schema, metadata, eq_id, form_type): # pylint: disable=unused-argument session_data = get_session_store().session_data completeness = get_completeness(current_user) if session_data.submitted_time: metadata_context = build_metadata_context_for_survey_completed( session_data) view_submission_url = None view_submission_duration = 0 if _is_submission_viewable(schema.json, session_data.submitted_time): view_submission_url = url_for('.get_view_submission', eq_id=eq_id, form_type=form_type) view_submission_duration = humanize.naturaldelta( timedelta(seconds=schema.json['view_submitted_response'] ['duration'])) return render_theme_template( schema.json['theme'], template_name='thank-you.html', metadata=metadata_context, analytics_ua_id=current_app.config['EQ_UA_ID'], survey_id=schema.json['survey_id'], survey_title=TemplateRenderer.safe_content(schema.json['title']), is_view_submitted_response_enabled= is_view_submitted_response_enabled(schema.json), view_submission_url=view_submission_url, view_submission_duration=view_submission_duration) routing_path = path_finder.get_full_routing_path() collection_id = metadata['collection_exercise_sid'] router = Router(schema, routing_path, completeness) next_location = router.get_next_location() return _redirect_to_location(collection_id, metadata.get('eq_id'), metadata.get('form_type'), next_location)