[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:
Rocky Meza 2014-12-26 22:27:37 -07:00
parent 00531ec937
commit 46b9a6acd9

View File

@ -309,15 +309,20 @@ class TestDynamicListAndDetailRouter(TestCase):
class TestRootWithAListlessViewset(TestCase):
def setUp(self):
class NoteViewSet(mixins.RetrieveModelMixin,
viewsets.GenericViewSet):
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)