def test_find_pointers_containing_list():
        schema = {
            "this": "is",
            "a": {
                "test": [
                    {"item": {}},
                    {"item": {}},
                    {"item": {}},
                    {"item": {}},
                    {"item": {}},
                ]
            },
        }

        pointers = find_pointers_containing(schema, "item")

        assert "/a/test/0" in pointers
        assert "/a/test/1" in pointers
        assert "/a/test/2" in pointers
        assert "/a/test/3" in pointers
        assert "/a/test/4" in pointers
Exemple #2
0
    def setUp(self):
        super().setUp()

        self.question_json = {
            "id":
            "confirm-date-of-birth-proxy",
            "title":
            "Confirm date of birth",
            "type":
            "General",
            "answers": [{
                "id":
                "confirm-date-of-birth-answer-proxy",
                "mandatory":
                True,
                "options": [
                    {
                        "label": {
                            "text":
                            "{person_name_possessive} age is {age}. Is this correct?",
                            "placeholders": [
                                {
                                    "placeholder":
                                    "person_name_possessive",
                                    "transforms": [
                                        {
                                            "arguments": {
                                                "delimiter": " ",
                                                "list_to_concatenate": {
                                                    "identifier": [
                                                        "first-name",
                                                        "last-name",
                                                    ],
                                                    "source":
                                                    "answers",
                                                },
                                            },
                                            "transform": "concatenate_list",
                                        },
                                        {
                                            "arguments": {
                                                "string_to_format": {
                                                    "source":
                                                    "previous_transform"
                                                }
                                            },
                                            "transform": "format_possessive",
                                        },
                                    ],
                                },
                                {
                                    "placeholder":
                                    "age",
                                    "transforms": [{
                                        "transform":
                                        "calculate_date_difference",
                                        "arguments": {
                                            "first_date": {
                                                "source":
                                                "answers",
                                                "identifier":
                                                "date-of-birth-answer",
                                            },
                                            "second_date": {
                                                "value": "now"
                                            },
                                        },
                                    }],
                                },
                            ],
                        },
                        "value": "Yes",
                    },
                    {
                        "label": "No, I need to change their date of birth",
                        "value": "No",
                    },
                ],
                "type":
                "Radio",
            }],
        }

        self.pointers = list(
            find_pointers_containing(self.question_json, "placeholders"))
    def test_find_pointers_containing_root():
        schema = {"test": ""}

        pointers = list(find_pointers_containing(schema, "test"))

        assert pointers == [""]
    def test_find_pointers_containing_element():
        schema = {"this": "is", "a": {"test": "schema"}}

        pointers = find_pointers_containing(schema, "test")

        assert "/a" in pointers