-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not allow to pass an empty actions to viewset.as_view(). Refs issue #…
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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({'METHOD': '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, {'METHOD': 'LIST'}) | ||
|
||
def test_initialize_view_set_with_empty_actions(self): | ||
try: | ||
BasicViewSet.as_view() | ||
except TypeError as e: | ||
self.assertEqual(str(e), "Your tried to pass an empty actions dict" | ||
". Don't do that.") | ||
else: | ||
self.fail("actions must not be empty.") |