mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-21 17:16:47 +03:00
Use str as default path converter (#9066)
This commit is contained in:
parent
9e05aa5962
commit
5c07060ce0
|
@ -144,7 +144,7 @@ class SimpleRouter(BaseRouter):
|
||||||
self._url_conf = re_path
|
self._url_conf = re_path
|
||||||
else:
|
else:
|
||||||
self._base_pattern = '<{lookup_value}:{lookup_prefix}{lookup_url_kwarg}>'
|
self._base_pattern = '<{lookup_value}:{lookup_prefix}{lookup_url_kwarg}>'
|
||||||
self._default_value_pattern = 'path'
|
self._default_value_pattern = 'str'
|
||||||
self._url_conf = path
|
self._url_conf = path
|
||||||
# remove regex characters from routes
|
# remove regex characters from routes
|
||||||
_routes = []
|
_routes = []
|
||||||
|
|
|
@ -99,6 +99,13 @@ class UrlPathViewSet(viewsets.ViewSet):
|
||||||
kwarg = self.kwargs.get('kwarg', '')
|
kwarg = self.kwargs.get('kwarg', '')
|
||||||
return Response({'pk': pk, 'kwarg': kwarg})
|
return Response({'pk': pk, 'kwarg': kwarg})
|
||||||
|
|
||||||
|
@action(detail=True, url_path='detail/<int:kwarg>/detail/<int:param>')
|
||||||
|
def url_path_detail_multiple_params(self, request, *args, **kwargs):
|
||||||
|
pk = self.kwargs.get('pk', '')
|
||||||
|
kwarg = self.kwargs.get('kwarg', '')
|
||||||
|
param = self.kwargs.get('param', '')
|
||||||
|
return Response({'pk': pk, 'kwarg': kwarg, 'param': param})
|
||||||
|
|
||||||
|
|
||||||
notes_router = SimpleRouter()
|
notes_router = SimpleRouter()
|
||||||
notes_router.register(r'notes', NoteViewSet)
|
notes_router.register(r'notes', NoteViewSet)
|
||||||
|
@ -561,6 +568,18 @@ class TestUrlPath(URLPatternsTestCase, TestCase):
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert json.loads(response.content.decode()) == {'pk': pk, 'kwarg': kwarg}
|
assert json.loads(response.content.decode()) == {'pk': pk, 'kwarg': kwarg}
|
||||||
|
|
||||||
|
def test_detail_extra_other_action(self):
|
||||||
|
# this to assure that ambiguous patterns are interpreted correctly
|
||||||
|
# using the `path` converters this URL is recognized to match the pattern
|
||||||
|
# of `UrlPathViewSet.url_path_detail` when it should match
|
||||||
|
# `UrlPathViewSet.url_path_detail_multiple_params`
|
||||||
|
pk = '1'
|
||||||
|
kwarg = 1234
|
||||||
|
param = 2
|
||||||
|
response = self.client.get('/path/1/detail/1234/detail/2/')
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert json.loads(response.content.decode()) == {'pk': pk, 'kwarg': kwarg, 'param': param}
|
||||||
|
|
||||||
def test_defaultrouter_root(self):
|
def test_defaultrouter_root(self):
|
||||||
response = self.client.get('/default/')
|
response = self.client.get('/default/')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
Loading…
Reference in New Issue
Block a user