mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 00:19:53 +03:00
Add tests also for default router with path
This commit is contained in:
parent
06a9244bc9
commit
ff69c69658
|
@ -96,6 +96,9 @@ notes_router.register(r'notes', NoteViewSet)
|
||||||
notes_path_router = SimpleRouter(use_regex_path=False)
|
notes_path_router = SimpleRouter(use_regex_path=False)
|
||||||
notes_path_router.register('notes', NoteViewSet)
|
notes_path_router.register('notes', NoteViewSet)
|
||||||
|
|
||||||
|
notes_path_default_router = DefaultRouter(use_regex_path=False)
|
||||||
|
notes_path_default_router.register('notes', NoteViewSet)
|
||||||
|
|
||||||
kwarged_notes_router = SimpleRouter()
|
kwarged_notes_router = SimpleRouter()
|
||||||
kwarged_notes_router.register(r'notes', KWargedNoteViewSet)
|
kwarged_notes_router.register(r'notes', KWargedNoteViewSet)
|
||||||
|
|
||||||
|
@ -484,7 +487,8 @@ class TestUrlPath(URLPatternsTestCase, TestCase):
|
||||||
client_class = APIClient
|
client_class = APIClient
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('path/', include(url_path_router.urls)),
|
path('path/', include(url_path_router.urls)),
|
||||||
path('example/', include(notes_path_router.urls))
|
path('default/', include(notes_path_default_router.urls)),
|
||||||
|
path('example/', include(notes_path_router.urls)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -503,13 +507,19 @@ class TestUrlPath(URLPatternsTestCase, TestCase):
|
||||||
assert RouterTestModel.objects.filter(uuid='foo').exists()
|
assert RouterTestModel.objects.filter(uuid='foo').exists()
|
||||||
|
|
||||||
def test_retrieve(self):
|
def test_retrieve(self):
|
||||||
response = self.client.get('/example/notes/123/')
|
for url in ('/example/notes/123/', '/default/notes/123/'):
|
||||||
|
with self.subTest(url=url):
|
||||||
|
response = self.client.get(url)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
# only gets example path since was the last to be registered
|
||||||
assert response.data == {"url": "http://testserver/example/notes/123/", "uuid": "123", "text": "foo bar"}
|
assert response.data == {"url": "http://testserver/example/notes/123/", "uuid": "123", "text": "foo bar"}
|
||||||
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
response = self.client.get('/example/notes/')
|
for url in ('/example/notes/', '/default/notes/'):
|
||||||
|
with self.subTest(url=url):
|
||||||
|
response = self.client.get(url)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
# only gets example path since was the last to be registered
|
||||||
assert response.data == [
|
assert response.data == [
|
||||||
{"url": "http://testserver/example/notes/123/", "uuid": "123", "text": "foo bar"},
|
{"url": "http://testserver/example/notes/123/", "uuid": "123", "text": "foo bar"},
|
||||||
{"url": "http://testserver/example/notes/a%20b/", "uuid": "a b", "text": "baz qux"},
|
{"url": "http://testserver/example/notes/a%20b/", "uuid": "a b", "text": "baz qux"},
|
||||||
|
@ -541,6 +551,12 @@ 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_defaultrouter_root(self):
|
||||||
|
response = self.client.get('/default/')
|
||||||
|
assert response.status_code == 200
|
||||||
|
# only gets example path since was the last to be registered
|
||||||
|
assert response.data == {"notes": "http://testserver/example/notes/"}
|
||||||
|
|
||||||
|
|
||||||
class TestViewInitkwargs(URLPatternsTestCase, TestCase):
|
class TestViewInitkwargs(URLPatternsTestCase, TestCase):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user