def test_new_comment_data_patch_to_many_relationship(self):
        entry = EntryFactory(blog=self.blog, authors=(self.author, ))
        comment = CommentFactory(entry=entry)

        url = '/authors/{}/relationships/comments'.format(self.author.id)
        request_data = {
            'data': [
                {
                    'type': format_resource_type('Comment'),
                    'id': str(comment.id)
                },
            ]
        }
        previous_response = {
            'data': [{
                'type': 'comments',
                'id': str(self.second_comment.id)
            }],
            'links': {
                'self':
                'http://testserver/authors/{}/relationships/comments'.format(
                    self.author.id)
            }
        }

        response = self.client.get(url)
        assert response.status_code == 200
        assert response.json() == previous_response

        new_patched_response = {
            'data': [{
                'type': 'comments',
                'id': str(comment.id)
            }],
            'links': {
                'self':
                'http://testserver/authors/{}/relationships/comments'.format(
                    self.author.id)
            }
        }

        response = self.client.patch(url, data=request_data)
        assert response.status_code == 200
        assert response.json() == new_patched_response

        assert Comment.objects.filter(id=self.second_comment.id).exists()
    def test_new_comment_data_patch_to_many_relationship(self):
        entry = EntryFactory(blog=self.blog, authors=(self.author, ))
        comment = CommentFactory(entry=entry)

        url = "/authors/{}/relationships/comments".format(self.author.id)
        request_data = {
            "data": [
                {
                    "type": format_resource_type("Comment"),
                    "id": str(comment.id)
                },
            ]
        }
        previous_response = {
            "data": [{
                "type": "comments",
                "id": str(self.second_comment.id)
            }],
            "links": {
                "self":
                "http://testserver/authors/{}/relationships/comments".format(
                    self.author.id)
            },
        }

        response = self.client.get(url)
        assert response.status_code == 200
        assert response.json() == previous_response

        new_patched_response = {
            "data": [{
                "type": "comments",
                "id": str(comment.id)
            }],
            "links": {
                "self":
                "http://testserver/authors/{}/relationships/comments".format(
                    self.author.id)
            },
        }

        response = self.client.patch(url, data=request_data)
        assert response.status_code == 200
        assert response.json() == new_patched_response

        assert Comment.objects.filter(id=self.second_comment.id).exists()