Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed forms_tests.tests.test_renderers with Jinja 3.1.0+. #15541

Merged
merged 1 commit into from Mar 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/forms_tests/tests/test_renderers.py
@@ -1,4 +1,5 @@
import os
import posixpath
import unittest

from django.forms.renderers import (
Expand All @@ -8,6 +9,7 @@
TemplatesSetting,
)
from django.test import SimpleTestCase
from django.utils.version import get_version_tuple

try:
import jinja2
Expand Down Expand Up @@ -50,6 +52,28 @@ class Jinja2Tests(SharedTests, SimpleTestCase):
renderer = Jinja2
expected_widget_dir = "jinja2"

@property
def jinja2_version(self):
return get_version_tuple(jinja2.__version__)

def test_installed_apps_template_found(self):
"""Can find a custom template in INSTALLED_APPS."""
renderer = self.renderer()
# Found because forms_tests is .
tpl = renderer.get_template("forms_tests/custom_widget.html")
expected_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", self.expected_widget_dir)
)
if self.jinja2_version < (3, 1):
expected_path = os.path.join(
expected_path, "forms_tests", "custom_widget.html"
)
else:
expected_path = posixpath.join(
expected_path, "forms_tests", "custom_widget.html"
)
self.assertEqual(tpl.origin.name, expected_path)


class TemplatesSettingTests(SharedTests, SimpleTestCase):
renderer = TemplatesSetting