Skip to content

Commit ba865d9

Browse files
committed
Fix test_urlpatterns.py to continue testing mixed re_path() and path()
1 parent 108993d commit ba865d9

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

tests/test_urlpatterns.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -142,43 +142,35 @@ def test_included_urls(self):
142142
]
143143
self._test_included_urls(urlpatterns)
144144

145-
def test_included_urls_django2(self):
146-
nested_patterns = [
147-
path('path', dummy_view)
148-
]
149-
urlpatterns = [
150-
path('test/', include(nested_patterns), {'foo': 'bar'}),
151-
]
152-
self._test_included_urls(urlpatterns)
153-
154-
def test_included_urls_django2_mixed(self):
155-
nested_patterns = [
156-
path('path', dummy_view)
157-
]
158-
urlpatterns = [
159-
path('test/', include(nested_patterns), {'foo': 'bar'}),
160-
]
161-
self._test_included_urls(urlpatterns)
162-
163-
def test_included_urls_django2_mixed_args(self):
145+
def test_included_urls_mixed(self):
164146
nested_patterns = [
165147
path('path/<int:child>', dummy_view),
166-
path('url/<int:child>', dummy_view)
148+
re_path(r'^re_path/(?P<child>[0-9]+)$', dummy_view)
167149
]
168150
urlpatterns = [
169-
path('purl/<int:parent>/', include(nested_patterns), {'foo': 'bar'}),
151+
re_path(r'^pre_path/(?P<parent>[0-9]+)/', include(nested_patterns), {'foo': 'bar'}),
170152
path('ppath/<int:parent>/', include(nested_patterns), {'foo': 'bar'}),
171153
]
172154
test_paths = [
173-
# parent url() nesting child path()
174-
URLTestPath('/purl/87/path/42', (), {'parent': 87, 'child': 42, 'foo': 'bar', }),
175-
URLTestPath('/purl/87/path/42.api', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'api'}),
176-
URLTestPath('/purl/87/path/42.asdf', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
155+
# parent re_path() nesting child path()
156+
URLTestPath('/pre_path/87/path/42', (), {'parent': '87', 'child': 42, 'foo': 'bar', }),
157+
URLTestPath('/pre_path/87/path/42.api', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'api'}),
158+
URLTestPath('/pre_path/87/path/42.asdf', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
159+
160+
# parent path() nesting child re_path()
161+
URLTestPath('/ppath/87/re_path/42', (), {'parent': 87, 'child': '42', 'foo': 'bar', }),
162+
URLTestPath('/ppath/87/re_path/42.api', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'api'}),
163+
URLTestPath('/ppath/87/re_path/42.asdf', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
177164

178165
# parent path() nesting child path()
179166
URLTestPath('/ppath/87/path/42', (), {'parent': 87, 'child': 42, 'foo': 'bar', }),
180167
URLTestPath('/ppath/87/path/42.api', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'api'}),
181168
URLTestPath('/ppath/87/path/42.asdf', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
169+
170+
# parent re_path() nesting child re_path()
171+
URLTestPath('/pre_path/87/re_path/42', (), {'parent': '87', 'child': '42', 'foo': 'bar', }),
172+
URLTestPath('/pre_path/87/re_path/42.api', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'api'}),
173+
URLTestPath('/pre_path/87/re_path/42.asdf', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
182174
]
183175
self._resolve_urlpatterns(urlpatterns, test_paths)
184176

@@ -191,13 +183,13 @@ def _test_allowed_formats(self, urlpatterns):
191183
]
192184
self._resolve_urlpatterns(urlpatterns, test_paths, allowed=allowed_formats)
193185

194-
def test_allowed_formats(self):
186+
def test_allowed_formats_re_path(self):
195187
urlpatterns = [
196-
path('test', dummy_view),
188+
re_path(r'^test$', dummy_view),
197189
]
198190
self._test_allowed_formats(urlpatterns)
199191

200-
def test_allowed_formats_django2(self):
192+
def test_allowed_formats_path(self):
201193
urlpatterns = [
202194
path('test', dummy_view),
203195
]

0 commit comments

Comments
 (0)