예제 #1
0
    def test_build_view_context_for_number_calculated_summary(self):
        current_location = Location(section_id="default-section",
                                    block_id="number-total-playback")

        calculated_summary_context = CalculatedSummaryContext(
            "cy",
            self.schema,
            self.answer_store,
            self.list_store,
            self.progress_store,
            self.metadata,
        )

        context = calculated_summary_context.build_view_context_for_calculated_summary(
            current_location)

        self.check_context(context)
        self.check_summary_rendering_context(context)
        self.assertEqual(len(context["summary"]), 6)
        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")
예제 #2
0
 def get_context(self):
     calculated_summary_context = CalculatedSummaryContext(
         self._language,
         self._schema,
         self._questionnaire_store.answer_store,
         self._questionnaire_store.list_store,
         self._questionnaire_store.progress_store,
         self._questionnaire_store.metadata,
     )
     return calculated_summary_context.build_view_context_for_calculated_summary(
         self._current_location)
    def test_build_view_context_for_currency_calculated_summary_with_skip(self):
        current_location = Location(
            section_id="default-section",
            block_id="currency-total-playback-skipped-fourth",
        )

        skip_answer = Answer("skip-fourth-block-answer", "Yes")
        self.answer_store.add_or_update(skip_answer)

        calculated_summary_context = CalculatedSummaryContext(
            "en",
            self.schema,
            self.answer_store,
            self.list_store,
            self.progress_store,
            self.metadata,
            self.response_metadata,
        )

        context = calculated_summary_context.build_view_context_for_calculated_summary(
            current_location
        )

        self.assertIn("summary", context)
        self.assert_summary_context(context)
        self.assertEqual(len(context["summary"]), 6)
        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):
        current_location = Location(
            section_id="default-section", block_id="currency-total-playback-with-fourth"
        )

        calculated_summary_context = CalculatedSummaryContext(
            "en",
            self.schema,
            self.answer_store,
            self.list_store,
            self.progress_store,
            self.metadata,
            self.response_metadata,
        )

        context = calculated_summary_context.build_view_context_for_calculated_summary(
            current_location
        )

        self.assertTrue("summary" in context, "Key value summary missing from context")
        self.assert_summary_context(context)
        self.assertEqual(len(context["summary"]), 6)
        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"]), 5)
        self.assertEqual(
            context_summary["calculated_question"]["title"],
            "Grand total of previous values",
        )
        self.assertEqual(
            context_summary["calculated_question"]["answers"][0]["value"], "£27.00"
        )