def test_build_view_context_for_calculated_summary_for_repeating_group( self): block_type = 'CalculatedSummary' schema_context = self.schema_context schema_context['group_instance_id'] = 'bbb-group-instance-id' current_location = Location('member-group', 1, 'currency-total-playback') context = build_view_context_for_calculated_summary( self.metadata, self.schema, self.answer_store, schema_context, block_type, self.variables, self.csrf_token, current_location) self.check_context(context) context_summary = context['summary'] self.assertEqual(len(context_summary['groups']), 1) self.assertEqual( context_summary['title'], 'We calculate the total of currency values entered for Bbb to be £24.00. Is this correct?' ) self.assertEqual( context_summary['groups'][0]['blocks'][0]['questions'][0] ['answers'][0]['value'], 2) self.assertEqual( context_summary['groups'][0]['blocks'][1]['questions'][0] ['answers'][0]['value'], 22)
def test_build_view_context_for_number_calculated_summary(self): csrf_token = None variables = None current_location = Location( block_id='number-total-playback', group_id='group', group_instance=0, ) context = build_view_context_for_calculated_summary( self.metadata, self.schema, self.answer_store, self.schema_context, self.block_type, variables, csrf_token, current_location) self.check_context(context) self.check_summary_rendering_context(context['summary']['groups']) self.assertEqual(len(context['summary']), 5) context_summary = context['summary'] self.assertTrue('title' in context_summary) self.assertEqual( context_summary['title'], 'We calculate the total of number values entered to be 22. Is this correct?' ) self.assertTrue('calculated_question' in context_summary) self.assertEqual(context_summary['calculated_question']['title'], 'Grand total of previous values') self.assertEqual( context_summary['calculated_question']['answers'][0]['value'], '22')
def test_build_view_context_for_calculated_summary_repeating_group(self): csrf_token = None variables = None group_instance = 2 answers = [ {'value': 10, 'answer_id': 'fifth-number-answer', 'group_instance': group_instance, 'answer_instance': 0}, {'value': 20, 'answer_id': 'sixth-number-answer', 'group_instance': group_instance, 'answer_instance': 0}, ] answer_store = AnswerStore(answers) current_location = Location( block_id='number-total-playback', group_id='group', group_instance=group_instance, ) with patch('app.questionnaire.questionnaire_schema.QuestionnaireSchema.answer_is_in_repeating_group', return_value=True): context = build_view_context_for_calculated_summary(self.metadata, self.schema, answer_store, self.schema_context, self.block_type, variables, csrf_token, current_location) self.check_context(context) self.assertEqual(len(context['summary']), 5) context_summary = context['summary'] self.assertTrue('title' in context_summary) self.assertEqual(context_summary['title'], 'We calculate the total of number values entered to be 30. Is this correct?') self.assertTrue('calculated_question' in context_summary) self.assertEqual(context_summary['calculated_question']['title'], 'Grand total of previous values') self.assertEqual(context_summary['calculated_question']['answers'][0]['value'], '30')
def test_build_view_context_for_currency_calculated_summary_with_skip( self): csrf_token = None variables = None current_location = Location( block_id='currency-total-playback', group_id='group', group_instance=0, ) skip_answer = Answer('skip-fourth-block-answer', 'Yes') self.answer_store.add_or_update(skip_answer) context = build_view_context_for_calculated_summary( self.metadata, self.schema, self.answer_store, self.schema_context, self.block_type, variables, csrf_token, current_location) self.check_context(context) self.check_summary_rendering_context(context['summary']['groups']) self.assertEqual(len(context['summary']), 5) context_summary = context['summary'] self.assertTrue('title' in context_summary) self.assertEqual(len(context_summary['groups'][0]['blocks']), 3) self.assertEqual( context_summary['title'], 'We calculate the total of currency values entered to be £12.00. Is this correct? (Skipped Fourth)' ) self.assertTrue('calculated_question' in context_summary) self.assertEqual(context_summary['calculated_question']['title'], 'Grand total of previous values') self.assertEqual( context_summary['calculated_question']['answers'][0]['value'], '£12.00')
def test_build_view_context_for_currency_calculated_summary_no_skip(self): variables = None current_location = Location( block_id='currency-total-playback', group_id='group', group_instance=0, ) context = build_view_context_for_calculated_summary( self.metadata, self.schema, self.answer_store, self.schema_context, self.block_type, variables, current_location) self.check_context(context) self.check_summary_rendering_context(context['summary']['groups']) self.assertEqual(len(context['summary']), 5) context_summary = context['summary'] self.assertTrue('title' in context_summary) self.assertEqual( context_summary['title'], 'We calculate the total of currency values entered to be £27.00. Is this correct? (With Fourth)' ) self.assertTrue('calculated_question' in context_summary) self.assertEqual(len(context_summary['groups'][0]['blocks']), 4) self.assertEqual(context_summary['calculated_question']['title'], 'Grand total of previous values') self.assertEqual( context_summary['calculated_question']['answers'][0]['value'], '£27.00')