def test_mandatory_mutually_exclusive_question_raises_error_with_question_text(
        self,
    ):
        with self.app_request_context():
            schema = load_schema_from_name("test_question_title_in_error")

            question_schema = schema.get_block("mutually-exclusive-checkbox").get(
                "question"
            )
            answer_store = AnswerStore(
                [{"answer_id": "mandatory-checkbox-answer", "value": ["Tuna"]}]
            )

            renderer = PlaceholderRenderer(
                language="en", schema=schema, answer_store=answer_store
            )
            rendered_schema = renderer.render(question_schema, None)

            form = generate_form(
                schema,
                rendered_schema,
                answer_store,
                metadata=None,
                form_data=MultiDict(),
            )
            form.validate_mutually_exclusive_question(question_schema)
            error = form.question_errors["mutually-exclusive-checkbox-question"]

            assert error == format_message_with_title(
                error_messages["MANDATORY_CHECKBOX"],
                "Did you really answer ‘Tuna’ to the previous question?",
            )
 def __post_init__(self) -> None:
     list_item_id = self.location.list_item_id if self.location else None
     self.value_source_resolver = ValueSourceResolver(
         answer_store=self.answer_store,
         list_store=self.list_store,
         metadata=self.metadata,
         response_metadata=self.response_metadata,
         schema=self.schema,
         location=self.location,
         list_item_id=list_item_id,
         routing_path_block_ids=self.routing_path_block_ids,
         use_default_answer=True,
     )
     renderer: PlaceholderRenderer = PlaceholderRenderer(
         language=self.language,
         answer_store=self.answer_store,
         list_store=self.list_store,
         metadata=self.metadata,
         response_metadata=self.response_metadata,
         schema=self.schema,
         location=self.location,
     )
     self.operations = Operations(language=self.language,
                                  schema=self.schema,
                                  renderer=renderer)
Ejemplo n.º 3
0
class Group:
    def __init__(
        self,
        group_schema,
        routing_path,
        answer_store,
        list_store,
        metadata,
        schema,
        location,
        language,
    ):
        self.id = group_schema["id"]

        self.title = group_schema.get("title")

        self.location = location

        self.blocks = self._build_blocks(
            group_schema,
            routing_path,
            answer_store,
            list_store,
            metadata,
            schema,
            location,
        )
        self.placeholder_renderer = PlaceholderRenderer(
            language=language,
            schema=schema,
            answer_store=answer_store,
            metadata=metadata,
        )

    @staticmethod
    def _build_blocks(group_schema, routing_path, answer_store, list_store,
                      metadata, schema, location):
        blocks = []

        for block in group_schema["blocks"]:
            if (block["id"] in routing_path and block["type"] == "Question"
                    and block.get("show_on_section_summary", True)):
                blocks.extend([
                    Block(block, answer_store, list_store, metadata, schema,
                          location).serialize()
                ])

        return blocks

    def serialize(self):
        return self.placeholder_renderer.render(
            {
                "id": self.id,
                "title": self.title,
                "blocks": self.blocks
            },
            self.location.list_item_id,
        )
Ejemplo n.º 4
0
def mock_renderer(mock_schema):
    return PlaceholderRenderer(
        language="en",
        answer_store=AnswerStore(),
        list_store=ListStore(),
        metadata=ImmutableDict({}),
        response_metadata={},
        schema=mock_schema,
    )
 def placeholder_renderer(self):
     return PlaceholderRenderer(
         language=self._language,
         answer_store=self._questionnaire_store.answer_store,
         list_store=self._questionnaire_store.list_store,
         metadata=self._questionnaire_store.metadata,
         response_metadata=self._questionnaire_store.response_metadata,
         schema=self._schema,
         location=None,
     )
Ejemplo n.º 6
0
def placeholder_renderer(option_label_from_value_schema):
    answer_store = AnswerStore(
        [
            {"answer_id": "mandatory-radio-answer", "value": "{body_parts}"},
            {"answer_id": "mandatory-checkbox-answer", "value": ["Body"]},
        ]
    )
    renderer = PlaceholderRenderer(
        language="en",
        answer_store=answer_store,
        list_store=ListStore(),
        metadata=ImmutableDict({"trad_as": "ESSENTIAL SERVICES LTD"}),
        response_metadata={},
        schema=option_label_from_value_schema,
    )
    return renderer
def get_placeholder_render(
    language="en",
    answer_store=AnswerStore(),
    list_store=ListStore(),
    metadata=None,
    response_metadata=None,
):
    renderer = PlaceholderRenderer(
        language=language,
        answer_store=answer_store,
        list_store=list_store,
        metadata=metadata or {},
        response_metadata=response_metadata or {},
        schema=Mock(),
    )
    return renderer