Example #1
0
    def test_simple(self):
        self.assertEqual(
            flatten_recursive_variables({
                "foo": "{{ bar }}",
                "bar": "hello world",
                "baz": "foo"
            }),
            ({
                "foo": "hello world",
                "bar": "hello world",
                "baz": "foo"
            }),
        )

        self.assertEqual(
            flatten_recursive_variables({
                "foo": "{{ bar }}",
                "bar": "hello world",
                "baz": None
            }),
            ({
                "foo": "hello world",
                "bar": "hello world",
                "baz": ""
            }),
        )
Example #2
0
 def test_complex(self):
     self.assertEqual(
         flatten_recursive_variables({
             "foo": "{{ bar }}",
             "bar": "hello {{ baz }}",
             "baz": "world{{end}}",
             "end": "!",
         }),
         ({
             "foo": "hello world!",
             "bar": "hello world!",
             "baz": "world!",
             "end": "!",
         }),
     )
Example #3
0
    def test_global_function_as_var_value(self):
        jinja_env = SandboxedEnvironment()
        jinja_env.globals.update(
            jinja_global_function_mock=self.jinja_global_function_mock)

        self.assertEqual(
            flatten_recursive_variables(
                {
                    "foo": "{{ jinja_global_function_mock() }}",
                },
                jinja_env,
            ),
            ({
                "foo": "bar",
            }),
        )
Example #4
0
    def test_global_function_vars_ignored(self):
        jinja_env = SandboxedEnvironment()
        jinja_env.globals.update(
            jinja_global_function_mock=self.jinja_global_function_mock)

        self.assertEqual(
            flatten_recursive_variables(
                {
                    "foo": "{{ bar }}",
                    "bar": "baz"
                },
                jinja_env,
            ),
            ({
                "foo": "baz",
                "bar": "baz"
            }),
        )