Ejemplo n.º 1
0
    def setUp(self):
        self.c = APIClient()
        self.user = create_user('user01')
        self.staff_user = create_user('staff01', is_staff=True)

        self.post01 = Post.objects.create(author=self.user,
                                          title="Post 01",
                                          text="Text of post 01.")
        self.comment01 = Comment.objects.create(post=self.post01,
                                                author=self.user,
                                                text="Text of comment 01.")
Ejemplo n.º 2
0
    def test_delete_by_not_author(self):
        other_user = create_user('other')

        login_user(self.c, other_user)

        response = self.c.delete(
            '/api/comment/{comment_id}/'.format(comment_id=self.comment01.id))

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 3
0
    def test_update_by_not_author(self):
        other_user = create_user('other')

        login_user(self.c, other_user)

        response = self.c.patch(
            '/api/comment/{comment_id}/'.format(comment_id=self.comment01.id),
            data={'text': "Updated text"})

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 4
0
    def test_delete_by_staff(self):
        staff_user = create_user('other', is_staff=True)

        login_user(self.c, staff_user)

        response = self.c.delete(
            '/api/comment/{comment_id}/'.format(comment_id=self.comment01.id))

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(
            Comment.objects.filter(id=self.comment01.id).exists(), False)
Ejemplo n.º 5
0
    def setUp(self):
        self.c = APIClient()
        self.user = create_user('user01')

        self.category01 = Category.objects.create(
            slug='cat01',
            name="Category 01"
        )
        self.post01 = Post.objects.create(
            author=self.user,
            title="Post 01",
            text="Text of post 01.",
            category=self.category01
        )