Ejemplo n.º 1
0
class RenderToStringTest(SimpleTestCase):
    def setUp(self):
        self.engine = Engine(dirs=[TEMPLATE_DIR])

    def test_basic_context(self):
        self.assertEqual(
            self.engine.render_to_string('test_context.html', {'obj': 'test'}),
            'obj:test\n',
        )
Ejemplo n.º 2
0
class RenderToStringTest(SimpleTestCase):

    def setUp(self):
        self.engine = Engine(dirs=[TEMPLATE_DIR])

    def test_basic_context(self):
        self.assertEqual(
            self.engine.render_to_string('test_context.html', {'obj': 'test'}),
            'obj:test\n',
        )
class DeprecatedRenderToStringTest(SimpleTestCase):

    def setUp(self):
        self.engine = Engine(
            dirs=[TEMPLATE_DIR],
            libraries={'custom': 'template_tests.templatetags.custom'},
        )

    def test_basic_context(self):
        self.assertEqual(
            self.engine.render_to_string('test_context.html', {'obj': 'test'}),
            'obj:test\n',
        )

    def test_existing_context_kept_clean(self):
        context = Context({'obj': 'before'})
        output = self.engine.render_to_string(
            'test_context.html', {'obj': 'after'}, context_instance=context,
        )
        self.assertEqual(output, 'obj:after\n')
        self.assertEqual(context['obj'], 'before')

    def test_no_empty_dict_pushed_to_stack(self):
        """
        #21741 -- An empty dict should not be pushed to the context stack when
        render_to_string is called without a context argument.
        """

        # The stack should have a length of 1, corresponding to the builtins
        self.assertEqual(
            '1',
            self.engine.render_to_string('test_context_stack.html').strip(),
        )
        self.assertEqual(
            '1',
            self.engine.render_to_string(
                'test_context_stack.html',
                context_instance=Context()
            ).strip(),
        )
Ejemplo n.º 4
0
class DeprecatedRenderToStringTest(SimpleTestCase):
    def setUp(self):
        self.engine = Engine(
            dirs=[TEMPLATE_DIR],
            libraries={'custom': 'template_tests.templatetags.custom'},
        )

    def test_basic_context(self):
        self.assertEqual(
            self.engine.render_to_string('test_context.html', {'obj': 'test'}),
            'obj:test\n',
        )

    def test_existing_context_kept_clean(self):
        context = Context({'obj': 'before'})
        output = self.engine.render_to_string(
            'test_context.html',
            {'obj': 'after'},
            context_instance=context,
        )
        self.assertEqual(output, 'obj:after\n')
        self.assertEqual(context['obj'], 'before')

    def test_no_empty_dict_pushed_to_stack(self):
        """
        #21741 -- An empty dict should not be pushed to the context stack when
        render_to_string is called without a context argument.
        """

        # The stack should have a length of 1, corresponding to the builtins
        self.assertEqual(
            '1',
            self.engine.render_to_string('test_context_stack.html').strip(),
        )
        self.assertEqual(
            '1',
            self.engine.render_to_string('test_context_stack.html',
                                         context_instance=Context()).strip(),
        )
Ejemplo n.º 5
0
class DeprecatedRenderToStringTest(SimpleTestCase):
    def setUp(self):
        self.engine = Engine(dirs=[TEMPLATE_DIR])

    def test_basic_context(self):
        self.assertEqual(self.engine.render_to_string("test_context.html", {"obj": "test"}), "obj:test\n")

    def test_existing_context_kept_clean(self):
        context = Context({"obj": "before"})
        output = self.engine.render_to_string("test_context.html", {"obj": "after"}, context_instance=context)
        self.assertEqual(output, "obj:after\n")
        self.assertEqual(context["obj"], "before")

    def test_no_empty_dict_pushed_to_stack(self):
        """
        #21741 -- An empty dict should not be pushed to the context stack when
        render_to_string is called without a context argument.
        """

        # The stack should have a length of 1, corresponding to the builtins
        self.assertEqual("1", self.engine.render_to_string("test_context_stack.html").strip())
        self.assertEqual(
            "1", self.engine.render_to_string("test_context_stack.html", context_instance=Context()).strip()
        )
Ejemplo n.º 6
0
class RenderToStringTest(SimpleTestCase):
    def setUp(self):
        self.engine = Engine(dirs=[TEMPLATE_DIR])

    def test_basic_context(self):
        self.assertEqual(
            self.engine.render_to_string('test_context.html', {'obj': 'test'}),
            'obj:test\n',
        )

    def test_autoescape_off(self):
        engine = Engine(dirs=[TEMPLATE_DIR], autoescape=False)
        self.assertEqual(
            engine.render_to_string('test_context.html', {'obj': '<script>'}),
            'obj:<script>\n',
        )
Ejemplo n.º 7
0
class RenderToStringTest(SimpleTestCase):
    def setUp(self):
        self.engine = Engine(dirs=[TEMPLATE_DIR])

    def test_basic_context(self):
        self.assertEqual(
            self.engine.render_to_string("test_context.html", {"obj": "test"}),
            "obj:test\n",
        )

    def test_autoescape_off(self):
        engine = Engine(dirs=[TEMPLATE_DIR], autoescape=False)
        self.assertEqual(
            engine.render_to_string("test_context.html", {"obj": "<script>"}),
            "obj:<script>\n",
        )
Ejemplo n.º 8
0
class RenderToStringTest(SimpleTestCase):

    def setUp(self):
        self.engine = Engine(dirs=[TEMPLATE_DIR])

    def test_basic_context(self):
        self.assertEqual(
            self.engine.render_to_string('test_context.html', {'obj': 'test'}),
            'obj:test\n',
        )

    def test_autoescape_off(self):
        engine = Engine(dirs=[TEMPLATE_DIR], autoescape=False)
        self.assertEqual(
            engine.render_to_string('test_context.html', {'obj': '<script>'}),
            'obj:<script>\n',
        )
Ejemplo n.º 9
0
class TemplateDirsOverrideTests(SimpleTestCase):
    DIRS = ((OTHER_DIR,), [OTHER_DIR])

    def setUp(self):
        self.engine = Engine()

    def test_render_to_string(self):
        for dirs in self.DIRS:
            self.assertEqual(self.engine.render_to_string("test_dirs.html", dirs=dirs), "spam eggs\n")

    def test_get_template(self):
        for dirs in self.DIRS:
            template = self.engine.get_template("test_dirs.html", dirs=dirs)
            self.assertEqual(template.render(Context()), "spam eggs\n")

    def test_select_template(self):
        for dirs in self.DIRS:
            template = self.engine.select_template(["test_dirs.html"], dirs=dirs)
            self.assertEqual(template.render(Context()), "spam eggs\n")
Ejemplo n.º 10
0
class TemplateDirsOverrideTests(SimpleTestCase):
    DIRS = ((OTHER_DIR, ), [OTHER_DIR])

    def setUp(self):
        self.engine = Engine()

    def test_render_to_string(self):
        for dirs in self.DIRS:
            self.assertEqual(
                self.engine.render_to_string('test_dirs.html', dirs=dirs),
                'spam eggs\n',
            )

    def test_get_template(self):
        for dirs in self.DIRS:
            template = self.engine.get_template('test_dirs.html', dirs=dirs)
            self.assertEqual(template.render(Context()), 'spam eggs\n')

    def test_select_template(self):
        for dirs in self.DIRS:
            template = self.engine.select_template(['test_dirs.html'], dirs=dirs)
            self.assertEqual(template.render(Context()), 'spam eggs\n')
Ejemplo n.º 11
0
 def test_autoescape_off(self):
     engine = Engine(dirs=[TEMPLATE_DIR], autoescape=False)
     self.assertEqual(
         engine.render_to_string('test_context.html', {'obj': '<script>'}),
         'obj:<script>\n',
     )
Ejemplo n.º 12
0
 def test_autoescape_off(self):
     engine = Engine(dirs=[TEMPLATE_DIR], autoescape=False)
     self.assertEqual(
         engine.render_to_string('test_context.html', {'obj': '<script>'}),
         'obj:<script>\n',
     )
Ejemplo n.º 13
0
 def test_autoescape_off(self):
     engine = Engine(dirs=[TEMPLATE_DIR], autoescape=False)
     self.assertEqual(
         engine.render_to_string("test_context.html", {"obj": "<script>"}),
         "obj:<script>\n",
     )