9
9
from django .test import TestCase , override_settings
10
10
11
11
from rest_framework import permissions , serializers , viewsets
12
+ from rest_framework .compat import get_regex_pattern
12
13
from rest_framework .decorators import detail_route , list_route
13
14
from rest_framework .response import Response
14
15
from rest_framework .routers import DefaultRouter , SimpleRouter
@@ -97,7 +98,7 @@ def regex_url_path_detail(self, request, *args, **kwargs):
97
98
98
99
urlpatterns = [
99
100
url (r'^non-namespaced/' , include (namespaced_router .urls )),
100
- url (r'^namespaced/' , include (namespaced_router .urls , namespace = 'example' , app_name = 'example' )),
101
+ url (r'^namespaced/' , include (( namespaced_router .urls , 'example' ), namespace = 'example' )),
101
102
url (r'^example/' , include (notes_router .urls )),
102
103
url (r'^example2/' , include (kwarged_notes_router .urls )),
103
104
@@ -176,7 +177,7 @@ def setUp(self):
176
177
177
178
def test_custom_lookup_field_route (self ):
178
179
detail_route = notes_router .urls [- 1 ]
179
- detail_url_pattern = detail_route . regex . pattern
180
+ detail_url_pattern = get_regex_pattern ( detail_route )
180
181
assert '<uuid>' in detail_url_pattern
181
182
182
183
def test_retrieve_lookup_field_list_view (self ):
@@ -213,7 +214,7 @@ class NoteViewSet(viewsets.ModelViewSet):
213
214
def test_urls_limited_by_lookup_value_regex (self ):
214
215
expected = ['^notes/$' , '^notes/(?P<uuid>[0-9a-f]{32})/$' ]
215
216
for idx in range (len (expected )):
216
- assert expected [idx ] == self .urls [idx ]. regex . pattern
217
+ assert expected [idx ] == get_regex_pattern ( self .urls [idx ])
217
218
218
219
219
220
@override_settings (ROOT_URLCONF = 'tests.test_routers' )
@@ -228,7 +229,7 @@ def setUp(self):
228
229
229
230
def test_custom_lookup_url_kwarg_route (self ):
230
231
detail_route = kwarged_notes_router .urls [- 1 ]
231
- detail_url_pattern = detail_route . regex . pattern
232
+ detail_url_pattern = get_regex_pattern ( detail_route )
232
233
assert '^notes/(?P<text>' in detail_url_pattern
233
234
234
235
def test_retrieve_lookup_url_kwarg_detail_view (self ):
@@ -252,7 +253,7 @@ class NoteViewSet(viewsets.ModelViewSet):
252
253
def test_urls_have_trailing_slash_by_default (self ):
253
254
expected = ['^notes/$' , '^notes/(?P<pk>[^/.]+)/$' ]
254
255
for idx in range (len (expected )):
255
- assert expected [idx ] == self .urls [idx ]. regex . pattern
256
+ assert expected [idx ] == get_regex_pattern ( self .urls [idx ])
256
257
257
258
258
259
class TestTrailingSlashRemoved (TestCase ):
@@ -267,7 +268,7 @@ class NoteViewSet(viewsets.ModelViewSet):
267
268
def test_urls_can_have_trailing_slash_removed (self ):
268
269
expected = ['^notes$' , '^notes/(?P<pk>[^/.]+)$' ]
269
270
for idx in range (len (expected )):
270
- assert expected [idx ] == self .urls [idx ]. regex . pattern
271
+ assert expected [idx ] == get_regex_pattern ( self .urls [idx ])
271
272
272
273
273
274
class TestNameableRoot (TestCase ):
0 commit comments