def test_build_list_summary_context(list_collector_block, people_answer_store,
                                    people_list_store):

    schema = load_schema_from_name("test_list_collector_primary_person")
    expected = [
        {
            "item_title": "Toni Morrison",
            "edit_link": "/questionnaire/people/PlwgoG/edit-person/",
            "remove_link": "/questionnaire/people/PlwgoG/remove-person/",
            "primary_person": False,
            "list_item_id": "PlwgoG",
        },
        {
            "item_title": "Barry Pheloung",
            "edit_link": "/questionnaire/people/UHPLbX/edit-person/",
            "remove_link": "/questionnaire/people/UHPLbX/remove-person/",
            "primary_person": False,
            "list_item_id": "UHPLbX",
        },
    ]

    list_context = ListContext(DEFAULT_LANGUAGE_CODE, schema,
                               people_answer_store, people_list_store, {},
                               None)

    list_context = list_context(
        list_collector_block["summary"],
        "people",
        edit_block_id=list_collector_block["edit_block"]["id"],
        remove_block_id=list_collector_block["remove_block"]["id"],
    )

    assert expected == list_context["list"]["list_items"]
def test_for_list_item_ids(list_collector_block, people_answer_store,
                           people_list_store):
    schema = load_schema_from_name("test_list_collector_primary_person")

    list_context = ListContext(
        language=DEFAULT_LANGUAGE_CODE,
        progress_store=ProgressStore(),
        list_store=people_list_store,
        schema=schema,
        answer_store=people_answer_store,
        metadata=None,
    )
    list_context = list_context(
        list_collector_block["summary"],
        list_collector_block["for_list"],
        for_list_item_ids=["UHPLbX"],
    )

    expected = [{
        "item_title": "Barry Pheloung",
        "primary_person": False,
        "list_item_id": "UHPLbX",
    }]

    assert expected == list_context["list"]["list_items"]
Beispiel #3
0
    def get_context(self):
        context = build_question_context(self.rendered_block, self.form)
        context["return_to_hub_url"] = self.get_return_to_hub_url()
        context[
            "last_viewed_question_guidance"] = self.get_last_viewed_question_guidance_context(
            )

        if "list_summary" in self.rendered_block:
            list_context = ListContext(
                self._language,
                self._schema,
                self._questionnaire_store.answer_store,
                self._questionnaire_store.list_store,
                self._questionnaire_store.progress_store,
                self._questionnaire_store.metadata,
            )

            context.update(
                list_context(
                    self.rendered_block["list_summary"]["summary"],
                    self.rendered_block["list_summary"]["for_list"],
                ))

        if self.form.errors or self.form.question_errors:
            self.page_title = gettext("Error: {page_title}").format(
                page_title=self.page_title)

        return context
Beispiel #4
0
 def list_context(self):
     return ListContext(
         self._language,
         self._schema,
         self._questionnaire_store.answer_store,
         self._questionnaire_store.list_store,
         self._questionnaire_store.progress_store,
         self._questionnaire_store.metadata,
     )
def test_build_list_summary_context_no_summary_block(schema,
                                                     people_answer_store,
                                                     people_list_store):
    list_context = ListContext(DEFAULT_LANGUAGE_CODE, schema,
                               people_answer_store, people_list_store, {},
                               None)

    list_context = list_context(None, for_list="people")

    assert list_context == {"list": {"editable": False, "list_items": []}}
def test_build_list_collector_context(list_collector_block, schema,
                                      people_answer_store, people_list_store):
    list_context = ListContext(DEFAULT_LANGUAGE_CODE, schema,
                               people_answer_store, people_list_store, {},
                               None)

    list_context = list_context(list_collector_block["summary"],
                                for_list="people")

    assert all(keys in list_context["list"].keys()
               for keys in ["list_items", "editable"])
    def get_context(self):
        question_context = super().get_context()
        list_context = ListContext(
            self._language,
            self._schema,
            self._questionnaire_store.answer_store,
            self._questionnaire_store.list_store,
            self._questionnaire_store.progress_store,
            self._questionnaire_store.metadata,
        )

        return {
            **question_context,
            **list_context(
                self.rendered_block["summary"],
                for_list=self.rendered_block["for_list"],
                edit_block_id=self.rendered_block["edit_block"]["id"],
                remove_block_id=self.rendered_block["remove_block"]["id"],
            ),
        }
def test_assert_primary_person_string_appended(list_collector_block,
                                               people_answer_store,
                                               people_list_store):
    schema = load_schema_from_name("test_list_collector_primary_person")
    people_list_store["people"].primary_person = "PlwgoG"

    list_context = ListContext(
        language=DEFAULT_LANGUAGE_CODE,
        progress_store=ProgressStore(),
        list_store=people_list_store,
        schema=schema,
        answer_store=people_answer_store,
        metadata=None,
    )
    list_context = list_context(list_collector_block["summary"],
                                list_collector_block["for_list"])

    assert list_context["list"]["list_items"][0]["primary_person"] is True
    assert list_context["list"]["list_items"][0][
        "item_title"] == "Toni Morrison (You)"
    assert list_context["list"]["list_items"][1][
        "item_title"] == "Barry Pheloung"
    def get_context(self):
        context = build_question_context(self.rendered_block, self.form)
        context["return_to_hub_url"] = self.get_return_to_hub_url()

        if "list_summary" in self.rendered_block:
            list_context = ListContext(
                self._language,
                self._schema,
                self._questionnaire_store.answer_store,
                self._questionnaire_store.list_store,
                self._questionnaire_store.progress_store,
                self._questionnaire_store.metadata,
            )

            context.update(
                list_context(
                    self.rendered_block["list_summary"]["summary"],
                    self.rendered_block["list_summary"]["for_list"],
                )
            )

        return context