def test_update_comment(self): """ Test update comment endpoint """ comment = CommentFactory() url = reverse('books:comments-detail', kwargs={'pk': comment.pk}) response = self.client.patch(url, {'text': 'New text'}) comment.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(response.data) self.assertTrue(comment.text, 'New text')
def test_get_comment(self): """ Test get detail comment endpoint """ comment = CommentFactory() url = reverse('books:comments-detail', kwargs={'pk': comment.pk}) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(response.data)
def test_delete_comment(self): """ Test delete comment endpoint """ comment = CommentFactory() url = reverse('books:comments-detail', kwargs={'pk': comment.pk}) response = self.client.delete(url) self.assertFalse(models.Comment.objects.filter(pk=comment.pk).exists())
def test_get_comments(self): """ Test get comments endpoint """ CommentFactory() response = self.client.get(reverse('books:comments-list')) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(response.data)