Fix test_urlpatterns.py to continue testing mixed re_path() and path()

This commit is contained in:
Adam Johnson 2020-09-02 13:07:09 +01:00
parent 108993dc7b
commit ba865d924e

View File

@ -142,43 +142,35 @@ class FormatSuffixTests(TestCase):
] ]
self._test_included_urls(urlpatterns) self._test_included_urls(urlpatterns)
def test_included_urls_django2(self): def test_included_urls_mixed(self):
nested_patterns = [
path('path', dummy_view)
]
urlpatterns = [
path('test/', include(nested_patterns), {'foo': 'bar'}),
]
self._test_included_urls(urlpatterns)
def test_included_urls_django2_mixed(self):
nested_patterns = [
path('path', dummy_view)
]
urlpatterns = [
path('test/', include(nested_patterns), {'foo': 'bar'}),
]
self._test_included_urls(urlpatterns)
def test_included_urls_django2_mixed_args(self):
nested_patterns = [ nested_patterns = [
path('path/<int:child>', dummy_view), path('path/<int:child>', dummy_view),
path('url/<int:child>', dummy_view) re_path(r'^re_path/(?P<child>[0-9]+)$', dummy_view)
] ]
urlpatterns = [ urlpatterns = [
path('purl/<int:parent>/', include(nested_patterns), {'foo': 'bar'}), re_path(r'^pre_path/(?P<parent>[0-9]+)/', include(nested_patterns), {'foo': 'bar'}),
path('ppath/<int:parent>/', include(nested_patterns), {'foo': 'bar'}), path('ppath/<int:parent>/', include(nested_patterns), {'foo': 'bar'}),
] ]
test_paths = [ test_paths = [
# parent url() nesting child path() # parent re_path() nesting child path()
URLTestPath('/purl/87/path/42', (), {'parent': 87, 'child': 42, 'foo': 'bar', }), URLTestPath('/pre_path/87/path/42', (), {'parent': '87', 'child': 42, 'foo': 'bar', }),
URLTestPath('/purl/87/path/42.api', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'api'}), URLTestPath('/pre_path/87/path/42.api', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'api'}),
URLTestPath('/purl/87/path/42.asdf', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'asdf'}), URLTestPath('/pre_path/87/path/42.asdf', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
# parent path() nesting child re_path()
URLTestPath('/ppath/87/re_path/42', (), {'parent': 87, 'child': '42', 'foo': 'bar', }),
URLTestPath('/ppath/87/re_path/42.api', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'api'}),
URLTestPath('/ppath/87/re_path/42.asdf', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
# parent path() nesting child path() # parent path() nesting child path()
URLTestPath('/ppath/87/path/42', (), {'parent': 87, 'child': 42, 'foo': 'bar', }), URLTestPath('/ppath/87/path/42', (), {'parent': 87, 'child': 42, 'foo': 'bar', }),
URLTestPath('/ppath/87/path/42.api', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'api'}), URLTestPath('/ppath/87/path/42.api', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'api'}),
URLTestPath('/ppath/87/path/42.asdf', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'asdf'}), URLTestPath('/ppath/87/path/42.asdf', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
# parent re_path() nesting child re_path()
URLTestPath('/pre_path/87/re_path/42', (), {'parent': '87', 'child': '42', 'foo': 'bar', }),
URLTestPath('/pre_path/87/re_path/42.api', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'api'}),
URLTestPath('/pre_path/87/re_path/42.asdf', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
] ]
self._resolve_urlpatterns(urlpatterns, test_paths) self._resolve_urlpatterns(urlpatterns, test_paths)
@ -191,13 +183,13 @@ class FormatSuffixTests(TestCase):
] ]
self._resolve_urlpatterns(urlpatterns, test_paths, allowed=allowed_formats) self._resolve_urlpatterns(urlpatterns, test_paths, allowed=allowed_formats)
def test_allowed_formats(self): def test_allowed_formats_re_path(self):
urlpatterns = [ urlpatterns = [
path('test', dummy_view), re_path(r'^test$', dummy_view),
] ]
self._test_allowed_formats(urlpatterns) self._test_allowed_formats(urlpatterns)
def test_allowed_formats_django2(self): def test_allowed_formats_path(self):
urlpatterns = [ urlpatterns = [
path('test', dummy_view), path('test', dummy_view),
] ]