mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
[don't merge] TestRootWithAListlessViewset problem
This modifies the TestDynamicListAndDetailRouter testcase to demonstrate that the way it is written is broken. Fortunately it is just the test that is broken and not the actual APIRoot code. The reason this test fails is that router created in TestRootWithAListlessViewset.setUp is never installed into the URLs. When APIRoot attempts to reverse the URLs in APIRoot.get. The URL reversal for the ListlessNoteViewSet should fail because it doesn't have a list action, but the FullNoteViewSet does have a list action, the reason it fails is that the URLs were never installed.
This commit is contained in:
parent
00531ec937
commit
46b9a6acd9
|
@ -309,15 +309,20 @@ class TestDynamicListAndDetailRouter(TestCase):
|
|||
|
||||
class TestRootWithAListlessViewset(TestCase):
|
||||
def setUp(self):
|
||||
class NoteViewSet(mixins.RetrieveModelMixin,
|
||||
class ListlessNoteViewSet(mixins.RetrieveModelMixin,
|
||||
viewsets.GenericViewSet):
|
||||
model = RouterTestModel
|
||||
|
||||
class FullNoteViewSet(viewsets.ModelViewSet):
|
||||
model = RouterTestModel
|
||||
|
||||
self.router = DefaultRouter()
|
||||
self.router.register(r'notes', NoteViewSet)
|
||||
self.router.register(r'listless', ListlessNoteViewSet, 'listless')
|
||||
self.router.register(r'listfull', ListlessNoteViewSet, 'listfull')
|
||||
self.view = self.router.urls[0].callback
|
||||
|
||||
def test_api_root(self):
|
||||
request = factory.get('/')
|
||||
response = self.view(request)
|
||||
self.assertEqual(response.data, {})
|
||||
self.assertIn('listfull', response.data)
|
||||
self.assertNotIn('listless', response.data)
|
||||
|
|
Loading…
Reference in New Issue
Block a user