Exemple #1
0
        def test_author_can_update_own_comment(self, api_client):
            new_comment = CommentFactory()
            api_client.force_authenticate(new_comment.author)
            data = {'title': 'updated title'}
            response = api_client.patch(new_comment.get_absolute_url(), data)

            assert response.status_code == 200
Exemple #2
0
        def test_not_author_cant_delete_comment(self, api_client):
            new_comment = CommentFactory()
            random_user = UserFactory()
            api_client.force_authenticate(random_user)
            response = api_client.delete(new_comment.get_absolute_url())

            assert response.status_code == 403
Exemple #3
0
        def test_comment_detail_page_render(self, api_client):
            new_comment = CommentFactory()
            api_client.force_authenticate(new_comment.author)

            response = api_client.get(new_comment.get_absolute_url())

            assert response.status_code == 200
Exemple #4
0
        def test_not_author_cant_update_comment(self, api_client):
            new_comment = CommentFactory()
            random_user = UserFactory()
            api_client.force_authenticate(random_user)
            data = {'title': 'updated title'}
            response = api_client.patch(new_comment.get_absolute_url(), data)

            assert response.status_code == 403
Exemple #5
0
        def test_guest_user_cant_update_comment(self, api_client):
            first_comment = CommentFactory()
            data = {'title': 'updated title'}
            response = api_client.patch(first_comment.get_absolute_url(), data)

            assert response.status_code == 401
Exemple #6
0
        def test_comment_delete(self, api_client):
            new_comment = CommentFactory()
            response = api_client.delete(new_comment.get_absolute_url())

            assert response.status_code == 401
Exemple #7
0
        def test_author_can_delete_own_comment(self, api_client):
            new_comment = CommentFactory()
            api_client.force_authenticate(new_comment.author)
            response = api_client.delete(new_comment.get_absolute_url())

            assert response.status_code == 204
Exemple #8
0
def test_get_absolute_url():
    new_comment = CommentFactory()

    assert new_comment.get_absolute_url() == reverse(
        'comments:detail', kwargs={"pk": new_comment.id})