diff options
author | Benjamin Wohlwend <piquadrat@gmail.com> | 2017-11-02 17:35:41 +0100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-12-06 18:05:40 -0500 |
commit | 79c196cfb287893aadc6b0e74603ffde1512170e (patch) | |
tree | 43133516a8b336d36ac3f9bf202d53cd731bbe44 /tests/urlpatterns | |
parent | ad191d9e011f37d79a7f2df3da881b06539aaaea (diff) | |
download | django-79c196cfb287893aadc6b0e74603ffde1512170e.tar.gz |
Fixed #28766 -- Added ResolverMatch.route.
Co-Authored-By: Xavier Fernandez <xavier.fernandez@polyconseil.fr>
Diffstat (limited to 'tests/urlpatterns')
-rw-r--r-- | tests/urlpatterns/included_urls.py | 3 | ||||
-rw-r--r-- | tests/urlpatterns/more_urls.py | 7 | ||||
-rw-r--r-- | tests/urlpatterns/path_urls.py | 4 | ||||
-rw-r--r-- | tests/urlpatterns/tests.py | 25 |
4 files changed, 37 insertions, 2 deletions
diff --git a/tests/urlpatterns/included_urls.py b/tests/urlpatterns/included_urls.py index d45e2764c5..76e4551f57 100644 --- a/tests/urlpatterns/included_urls.py +++ b/tests/urlpatterns/included_urls.py @@ -1,7 +1,8 @@ -from django.urls import path +from django.urls import include, path from . import views urlpatterns = [ path('extra/<extra>/', views.empty_view, name='inner-extra'), + path('', include('urlpatterns.more_urls')), ] diff --git a/tests/urlpatterns/more_urls.py b/tests/urlpatterns/more_urls.py new file mode 100644 index 0000000000..c7d789dda0 --- /dev/null +++ b/tests/urlpatterns/more_urls.py @@ -0,0 +1,7 @@ +from django.urls import re_path + +from . import views + +urlpatterns = [ + re_path(r'^more/(?P<extra>\w+)/$', views.empty_view, name='inner-more'), +] diff --git a/tests/urlpatterns/path_urls.py b/tests/urlpatterns/path_urls.py index 857ec0cd0b..4c80c840d9 100644 --- a/tests/urlpatterns/path_urls.py +++ b/tests/urlpatterns/path_urls.py @@ -1,5 +1,5 @@ from django.conf.urls import include -from django.urls import path +from django.urls import path, re_path from . import views @@ -11,5 +11,7 @@ urlpatterns = [ path('users/', views.empty_view, name='users'), path('users/<id>/', views.empty_view, name='user-with-id'), path('included_urls/', include('urlpatterns.included_urls')), + re_path(r'^regex/(?P<pk>[0-9]+)/$', views.empty_view, name='regex'), + path('', include('urlpatterns.more_urls')), path('<lang>/<path:url>/', views.empty_view, name='lang-and-path'), ] diff --git a/tests/urlpatterns/tests.py b/tests/urlpatterns/tests.py index 299258e56f..845d76c7af 100644 --- a/tests/urlpatterns/tests.py +++ b/tests/urlpatterns/tests.py @@ -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') |