diff options
Diffstat (limited to 'tests/urlpatterns')
| -rw-r--r-- | tests/urlpatterns/path_urls.py | 5 | ||||
| -rw-r--r-- | tests/urlpatterns/tests.py | 10 |
2 files changed, 15 insertions, 0 deletions
diff --git a/tests/urlpatterns/path_urls.py b/tests/urlpatterns/path_urls.py index b40801b39d..afc15f30af 100644 --- a/tests/urlpatterns/path_urls.py +++ b/tests/urlpatterns/path_urls.py @@ -12,6 +12,11 @@ urlpatterns = [ path('included_urls/', include('urlpatterns.included_urls')), re_path(r'^regex/(?P<pk>[0-9]+)/$', views.empty_view, name='regex'), re_path(r'^regex_optional/(?P<arg1>\d+)/(?:(?P<arg2>\d+)/)?', views.empty_view, name='regex_optional'), + re_path( + r'^regex_only_optional/(?:(?P<arg1>\d+)/)?', + views.empty_view, + name='regex_only_optional', + ), 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 92c4e6399e..b149e0d512 100644 --- a/tests/urlpatterns/tests.py +++ b/tests/urlpatterns/tests.py @@ -68,6 +68,16 @@ class SimplifiedURLTests(SimpleTestCase): r'^regex_optional/(?P<arg1>\d+)/(?:(?P<arg2>\d+)/)?', ) + def test_re_path_with_missing_optional_parameter(self): + match = resolve('/regex_only_optional/') + self.assertEqual(match.url_name, 'regex_only_optional') + self.assertEqual(match.kwargs, {}) + self.assertEqual(match.args, ()) + self.assertEqual( + match.route, + r'^regex_only_optional/(?:(?P<arg1>\d+)/)?', + ) + def test_path_lookup_with_inclusion(self): match = resolve('/included_urls/extra/something/') self.assertEqual(match.url_name, 'inner-extra') |
