Пример #1
0
    def test_destroy_like_comment_without_params(self):
        """
        Ensure we can destroy like comment without params
        """
        factory = APIRequestFactory()
        user = utils.create_user()
        comment = utils.create_comment(user)
        view = views.LikeCommentViewSet.as_view({
            'post': 'create',
            'delete': 'destroy'
        })

        # Create
        url = self.get_url_endpoint
        request = factory.post(url, {
            'users': str(user.pk),
            'comment': comment.pk
        })
        force_authenticate(request, user=user)
        response = view(request)

        # Delete
        url = self.get_url_endpoint + str(comment.pk) + "/"
        request = factory.delete(url)
        force_authenticate(request, user=user)
        response = view(request, pk=comment.pk)

        self.assertEqual(response.status_code == 404, True)
Пример #2
0
 def test_get_comment(self):
     """
     Ensure we can get comment
     """
     user = utils.create_user()
     comment = utils.create_comment(user)
     url = self.get_url_endpoint + str(comment.pk) + "/"
     response = self.client.get(url, format='json')
     self.assertEqual(response.status_code == 200, True)
Пример #3
0
    def test_destroy_comment(self):
        """
        Ensure we can destroy comment
        """
        factory = APIRequestFactory()
        user = utils.create_user()
        comment = utils.create_comment(user)
        view = views.CommentViewSet.as_view({'delete': 'destroy'})

        # Delete
        url = self.get_url_endpoint + str(comment.pk) + "/"
        request = factory.delete(url)
        force_authenticate(request, user=user)
        response = view(request, pk=comment.pk)

        self.assertEqual(response.status_code == 204, True)
Пример #4
0
    def test_update_comment(self):
        """
        Ensure we can update comment
        """
        factory = APIRequestFactory()
        user = utils.create_user()
        comment = utils.create_comment(user)
        view = views.CommentViewSet.as_view({
            'patch': 'update'
        })

        # Update
        url = self.get_url_endpoint + str(comment.pk) + "/"

        self.data = {
            "data": {
                "attributes": {
                    "total_likes": comment.total_likes,
                    "date": None,
                    "description": "<p>Test create comment edited</p>",
                },
                "id": comment.pk,
                "relationships": {
                    "user": {
                        "data": {
                            'id': str(user.pk),
                            'type': 'users'
                        }
                    },
                    "topic": {
                        "data": {
                            'id': str(comment.topic.pk),
                            'type': 'topics'
                        }
                    }
                },
                "type": "comments"
            },
        }

        request = factory.patch(
            url, json.dumps(self.data),
            HTTP_HOST='example.com', content_type="application/vnd.api+json"
        )
        force_authenticate(request, user=user)
        response = view(request, pk=comment.pk)
        self.assertEqual(response.status_code == 200, True)
Пример #5
0
    def test_create_like_comment(self):
        """
        Ensure we can create like comment
        """
        factory = APIRequestFactory()
        user = utils.create_user()
        comment = utils.create_comment(user)
        view = views.LikeCommentViewSet.as_view({'post': 'create'})

        url = self.get_url_endpoint
        request = factory.post(url, {
            'users': str(user.pk),
            'comment': comment.pk
        })
        force_authenticate(request, user=user)
        response = view(request)

        self.assertEqual(response.status_code == 200, True)