[Django]-Django Rest Framework Test case issue: 'HttpResponseNotAllowed' object has no attribute 'data'

6👍

Try using the DRF extended test client:

from rest_framework import status
from rest_framework.test import APITestCase, APIClient

class CategoryTests(APITestCase):
  client = APIClient()

  def test_create_create(self):

    url = '/category/add/'
    data = {"name":"Sports","description":"get live updates here"}
    response = self.client.post(url, data, format='json')
    self.assertEquals(response.data, data)

1👍

Issue was with url, I correct it and it worked. So my url was actually

url = '/v1.0/category/add/'
👤Neo

Leave a comment