mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #28766 -- Added ResolverMatch.route.
Co-Authored-By: Xavier Fernandez <xavier.fernandez@polyconseil.fr>
This commit is contained in:
committed by
Tim Graham
parent
ad191d9e01
commit
79c196cfb2
@@ -26,23 +26,48 @@ class SimplifiedURLTests(SimpleTestCase):
|
||||
self.assertEqual(match.url_name, 'articles-2003')
|
||||
self.assertEqual(match.args, ())
|
||||
self.assertEqual(match.kwargs, {})
|
||||
self.assertEqual(match.route, 'articles/2003/')
|
||||
|
||||
def test_path_lookup_with_typed_parameters(self):
|
||||
match = resolve('/articles/2015/')
|
||||
self.assertEqual(match.url_name, 'articles-year')
|
||||
self.assertEqual(match.args, ())
|
||||
self.assertEqual(match.kwargs, {'year': 2015})
|
||||
self.assertEqual(match.route, 'articles/<int:year>/')
|
||||
|
||||
def test_path_lookup_with_multiple_paramaters(self):
|
||||
match = resolve('/articles/2015/04/12/')
|
||||
self.assertEqual(match.url_name, 'articles-year-month-day')
|
||||
self.assertEqual(match.args, ())
|
||||
self.assertEqual(match.kwargs, {'year': 2015, 'month': 4, 'day': 12})
|
||||
self.assertEqual(match.route, 'articles/<int:year>/<int:month>/<int:day>/')
|
||||
|
||||
def test_two_variable_at_start_of_path_pattern(self):
|
||||
match = resolve('/en/foo/')
|
||||
self.assertEqual(match.url_name, 'lang-and-path')
|
||||
self.assertEqual(match.kwargs, {'lang': 'en', 'url': 'foo'})
|
||||
self.assertEqual(match.route, '<lang>/<path:url>/')
|
||||
|
||||
def test_re_path(self):
|
||||
match = resolve('/regex/1/')
|
||||
self.assertEqual(match.url_name, 'regex')
|
||||
self.assertEqual(match.kwargs, {'pk': '1'})
|
||||
self.assertEqual(match.route, '^regex/(?P<pk>[0-9]+)/$')
|
||||
|
||||
def test_path_lookup_with_inclusion(self):
|
||||
match = resolve('/included_urls/extra/something/')
|
||||
self.assertEqual(match.url_name, 'inner-extra')
|
||||
self.assertEqual(match.route, 'included_urls/extra/<extra>/')
|
||||
|
||||
def test_path_lookup_with_empty_string_inclusion(self):
|
||||
match = resolve('/more/99/')
|
||||
self.assertEqual(match.url_name, 'inner-more')
|
||||
self.assertEqual(match.route, r'^more/(?P<extra>\w+)/$')
|
||||
|
||||
def test_path_lookup_with_double_inclusion(self):
|
||||
match = resolve('/included_urls/more/some_value/')
|
||||
self.assertEqual(match.url_name, 'inner-more')
|
||||
self.assertEqual(match.route, r'included_urls/more/(?P<extra>\w+)/$')
|
||||
|
||||
def test_path_reverse_without_parameter(self):
|
||||
url = reverse('articles-2003')
|
||||
|
||||
Reference in New Issue
Block a user