mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Refs #24121 -- Added__repr__() to StaticNode.
This commit is contained in:
parent
34363a391b
commit
e6406853c3
@ -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)
|
||||
|
@ -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')",
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user