Refs #24121 -- Added __repr__() to URLNode.
This commit is contained in:
parent
5fd4f22d19
commit
d3ecef26b9
|
@ -406,6 +406,15 @@ class URLNode(Node):
|
|||
self.kwargs = kwargs
|
||||
self.asvar = asvar
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s view_name='%s' args=%s kwargs=%s as=%s>" % (
|
||||
self.__class__.__qualname__,
|
||||
self.view_name,
|
||||
repr(self.args),
|
||||
repr(self.kwargs),
|
||||
repr(self.asvar),
|
||||
)
|
||||
|
||||
def render(self, context):
|
||||
from django.urls import NoReverseMatch, reverse
|
||||
args = [arg.resolve(context) for arg in self.args]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from django.template import RequestContext, TemplateSyntaxError
|
||||
from django.template.defaulttags import URLNode
|
||||
from django.test import RequestFactory, SimpleTestCase, override_settings
|
||||
from django.urls import NoReverseMatch, resolve
|
||||
|
||||
|
@ -271,3 +272,23 @@ class UrlTagTests(SimpleTestCase):
|
|||
context = RequestContext(request)
|
||||
output = template.render(context)
|
||||
self.assertEqual(output, '/ns2/named-client/42/')
|
||||
|
||||
|
||||
class URLNodeTest(SimpleTestCase):
|
||||
def test_repr(self):
|
||||
url_node = URLNode(view_name='named-view', args=[], kwargs={}, asvar=None)
|
||||
self.assertEqual(
|
||||
repr(url_node),
|
||||
"<URLNode view_name='named-view' args=[] kwargs={} as=None>",
|
||||
)
|
||||
url_node = URLNode(
|
||||
view_name='named-view',
|
||||
args=[1, 2],
|
||||
kwargs={'action': 'update'},
|
||||
asvar='my_url',
|
||||
)
|
||||
self.assertEqual(
|
||||
repr(url_node),
|
||||
"<URLNode view_name='named-view' args=[1, 2] "
|
||||
"kwargs={'action': 'update'} as='my_url'>",
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue