Beispiel #1
0
    def test_errors_on_invalid_pointer(self):
        renderer = PlaceholderRenderer(language="en", schema=Mock())

        with self.assertRaises(ValueError):
            renderer.render_pointer(self.question_json,
                                    "/title",
                                    list_item_id=None)
Beispiel #2
0
    def test_errors_on_invalid_json(self):
        renderer = PlaceholderRenderer(language="en", schema=Mock())

        with self.assertRaises(ValueError):
            dict_to_render = {"invalid": {"no": "placeholders", "in": "this"}}
            renderer.render_pointer(dict_to_render,
                                    "/invalid",
                                    list_item_id=None)
Beispiel #3
0
    def test_renders_pointer(self):
        mock_transform = {
            "transform": "calculate_date_difference",
            "arguments": {
                "first_date": {
                    "source": "answers",
                    "identifier": "date-of-birth-answer",
                },
                "second_date": {"value": "2019-02-01"},
            },
        }

        json_to_render = self.question_json.copy()
        json_to_render["answers"][0]["options"][0]["label"]["placeholders"][1][
            "transforms"
        ][0] = mock_transform

        renderer = PlaceholderRenderer(
            language="en",
            schema=QuestionnaireSchema({}),
            answer_store=AnswerStore(
                [
                    {"answer_id": "first-name", "value": "Hal"},
                    {"answer_id": "last-name", "value": "Abelson"},
                    {"answer_id": "date-of-birth-answer", "value": "1991-01-01"},
                ]
            ),
        )

        rendered = renderer.render_pointer(
            self.question_json, "/answers/0/options/0/label", list_item_id=None
        )

        assert rendered == "Hal Abelson’s age is 28 years. Is this correct?"