from pathlib import Path from unittest import mock, skipIf from django.template import TemplateSyntaxError from django.test import RequestFactory from .test_dummy import TemplateStringsTests try: import jinja2 except ImportError: jinja2 = None Jinja2 = None else: from django.template.backends.jinja2 import Jinja2 @skipIf(jinja2 is None, "this test requires jinja2") class Jinja2Tests(TemplateStringsTests): engine_class = Jinja2 backend_name = "jinja2" options = { "keep_trailing_newline": True, "context_processors": [ "django.template.context_processors.static", ], } def test_origin(self): template = self.engine.get_template("template_backends/hello.html") self.assertTrue(template.origin.name.endswith("hello.html")) self.assertEqual(template.origin.template_name, "template_backends/hello.html") def test_origin_from_string(self): template = self.engine.from_string("Hello!\n") self.assertEqual(template.origin.name, "