From e6406853c326ea9210d07766138d2b193c6d1fba Mon Sep 17 00:00:00 2001 From: saeedblanchette Date: Sun, 9 May 2021 05:33:39 +0000 Subject: [PATCH] Refs #24121 -- Added__repr__() to StaticNode. --- django/templatetags/static.py | 5 +++++ tests/template_tests/syntax_tests/test_static.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/django/templatetags/static.py b/django/templatetags/static.py index 39712aaba08..71271d2410d 100644 --- a/django/templatetags/static.py +++ b/django/templatetags/static.py @@ -98,6 +98,11 @@ class StaticNode(template.Node): self.path = path self.varname = varname + def __repr__(self): + return ( + f'{self.__class__.__name__}(varname={self.varname!r}, path={self.path!r})' + ) + def url(self, context): path = self.path.resolve(context) return self.handle_simple(path) diff --git a/tests/template_tests/syntax_tests/test_static.py b/tests/template_tests/syntax_tests/test_static.py index 6f4908ac2cd..6f27d555bf6 100644 --- a/tests/template_tests/syntax_tests/test_static.py +++ b/tests/template_tests/syntax_tests/test_static.py @@ -2,6 +2,7 @@ from urllib.parse import urljoin from django.conf import settings from django.template import TemplateSyntaxError +from django.templatetags.static import StaticNode from django.test import SimpleTestCase, override_settings from ..utils import setup @@ -69,3 +70,17 @@ class StaticTagTests(SimpleTestCase): msg = "'static' takes at least one argument (path to file)" with self.assertRaisesMessage(TemplateSyntaxError, msg): self.engine.render_to_string('t') + + +class StaticNodeTests(SimpleTestCase): + def test_repr(self): + static_node = StaticNode(varname='named-var', path='named-path') + self.assertEqual( + repr(static_node), + "StaticNode(varname='named-var', path='named-path')", + ) + static_node = StaticNode(path='named-path') + self.assertEqual( + repr(static_node), + "StaticNode(varname=None, path='named-path')", + )