|
3 | 3 |
|
4 | 4 | from django.test import RequestFactory, override_settings
|
5 | 5 | from django.utils import timezone
|
6 |
| -from rest_framework import status |
7 |
| -from rest_framework.decorators import action |
8 | 6 | from rest_framework.exceptions import NotFound
|
9 | 7 | from rest_framework.request import Request
|
10 |
| -from rest_framework.response import Response |
11 | 8 | from rest_framework.reverse import reverse
|
12 | 9 | from rest_framework.test import APIRequestFactory, APITestCase, force_authenticate
|
13 | 10 |
|
14 |
| -from rest_framework_json_api import serializers, views |
15 | 11 | from rest_framework_json_api.utils import format_resource_type
|
16 | 12 |
|
17 | 13 | from example.factories import AuthorFactory, CommentFactory, EntryFactory
|
@@ -713,80 +709,3 @@ def test_get_object_gives_correct_entry(self):
|
713 | 709 | }
|
714 | 710 | got = resp.json()
|
715 | 711 | self.assertEqual(got, expected)
|
716 |
| - |
717 |
| - |
718 |
| -class BasicAuthorSerializer(serializers.ModelSerializer): |
719 |
| - class Meta: |
720 |
| - model = Author |
721 |
| - fields = ("name",) |
722 |
| - |
723 |
| - |
724 |
| -class ReadOnlyViewSetWithCustomActions(views.ReadOnlyModelViewSet): |
725 |
| - queryset = Author.objects.all() |
726 |
| - serializer_class = BasicAuthorSerializer |
727 |
| - |
728 |
| - @action(detail=False, methods=["get", "post", "patch", "delete"]) |
729 |
| - def group_action(self, request): |
730 |
| - return Response(status=status.HTTP_204_NO_CONTENT) |
731 |
| - |
732 |
| - @action(detail=True, methods=["get", "post", "patch", "delete"]) |
733 |
| - def item_action(self, request, pk): |
734 |
| - return Response(status=status.HTTP_204_NO_CONTENT) |
735 |
| - |
736 |
| - |
737 |
| -class TestReadonlyModelViewSet(TestBase): |
738 |
| - """ |
739 |
| - Test if ReadOnlyModelViewSet allows to have custom actions with POST, PATCH, DELETE methods |
740 |
| - """ |
741 |
| - |
742 |
| - factory = RequestFactory() |
743 |
| - viewset_class = ReadOnlyViewSetWithCustomActions |
744 |
| - media_type = "application/vnd.api+json" |
745 |
| - |
746 |
| - def test_group_action_allows_get(self): |
747 |
| - view = self.viewset_class.as_view({"get": "group_action"}) |
748 |
| - request = self.factory.get("/") |
749 |
| - response = view(request) |
750 |
| - self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) |
751 |
| - |
752 |
| - def test_group_action_allows_post(self): |
753 |
| - view = self.viewset_class.as_view({"post": "group_action"}) |
754 |
| - request = self.factory.post("/", "{}", content_type=self.media_type) |
755 |
| - response = view(request) |
756 |
| - self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) |
757 |
| - |
758 |
| - def test_group_action_allows_patch(self): |
759 |
| - view = self.viewset_class.as_view({"patch": "group_action"}) |
760 |
| - request = self.factory.patch("/", "{}", content_type=self.media_type) |
761 |
| - response = view(request) |
762 |
| - self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) |
763 |
| - |
764 |
| - def test_group_action_allows_delete(self): |
765 |
| - view = self.viewset_class.as_view({"delete": "group_action"}) |
766 |
| - request = self.factory.delete("/", "{}", content_type=self.media_type) |
767 |
| - response = view(request) |
768 |
| - self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) |
769 |
| - |
770 |
| - def test_item_action_allows_get(self): |
771 |
| - view = self.viewset_class.as_view({"get": "item_action"}) |
772 |
| - request = self.factory.get("/") |
773 |
| - response = view(request, pk="1") |
774 |
| - self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) |
775 |
| - |
776 |
| - def test_item_action_allows_post(self): |
777 |
| - view = self.viewset_class.as_view({"post": "item_action"}) |
778 |
| - request = self.factory.post("/", "{}", content_type=self.media_type) |
779 |
| - response = view(request, pk="1") |
780 |
| - self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) |
781 |
| - |
782 |
| - def test_item_action_allows_patch(self): |
783 |
| - view = self.viewset_class.as_view({"patch": "item_action"}) |
784 |
| - request = self.factory.patch("/", "{}", content_type=self.media_type) |
785 |
| - response = view(request, pk="1") |
786 |
| - self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) |
787 |
| - |
788 |
| - def test_item_action_allows_delete(self): |
789 |
| - view = self.viewset_class.as_view({"delete": "item_action"}) |
790 |
| - request = self.factory.delete("/", "{}", content_type=self.media_type) |
791 |
| - response = view(request, pk="1") |
792 |
| - self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) |
0 commit comments