aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTom Christie2014-12-03 08:53:04 +0000
committerTom Christie2014-12-03 08:53:04 +0000
commitc5a2d501e56201c437118aa65004b33d20216b55 (patch)
tree6ac80f166d405ab3c4f0443b0f15bd6a574039f5 /tests
parent71a8cb2282d2cb5cb92e74975f762bbdf8ff0d69 (diff)
parent53f52765fc90472a05cbeb34760b45f735a7332c (diff)
downloaddjango-rest-framework-c5a2d501e56201c437118aa65004b33d20216b55.tar.bz2
Merge pull request #2175 from BrickXu/fix_2171
Not allow to pass an empty actions to viewset.as_view()
Diffstat (limited to 'tests')
-rw-r--r--tests/test_viewsets.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_viewsets.py b/tests/test_viewsets.py
new file mode 100644
index 00000000..4d18a955
--- /dev/null
+++ b/tests/test_viewsets.py
@@ -0,0 +1,35 @@
+from django.test import TestCase
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.test import APIRequestFactory
+from rest_framework.viewsets import GenericViewSet
+
+
+factory = APIRequestFactory()
+
+
+class BasicViewSet(GenericViewSet):
+ def list(self, request, *args, **kwargs):
+ return Response({'ACTION': 'LIST'})
+
+
+class InitializeViewSetsTestCase(TestCase):
+ def test_initialize_view_set_with_actions(self):
+ request = factory.get('/', '', content_type='application/json')
+ my_view = BasicViewSet.as_view(actions={
+ 'get': 'list',
+ })
+
+ response = my_view(request)
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ self.assertEqual(response.data, {'ACTION': 'LIST'})
+
+ def test_initialize_view_set_with_empty_actions(self):
+ try:
+ BasicViewSet.as_view()
+ except TypeError as e:
+ self.assertEqual(str(e), "The `actions` argument must be provided "
+ "when calling `.as_view()` on a ViewSet. "
+ "For example `.as_view({'get': 'list'})`")
+ else:
+ self.fail("actions must not be empty.")