I executed this code:
from django.core.urlresolvers import reverse from rest_framework import status from rest_framework.test import APITestCase class AccountTests(APITestCase): def test_create_account(self): """ Ensure we can create a new account object. """ url = reverse('account-list') data = {'name': 'DabApps'} response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data, data)
Found in django-rest-framewok docs here:
http://www.django-rest-framework.org/api-guide/testing/#example
I created a single Model with a single name field and I still get the "bad request 400" error. The reverse name and title are also configured correctly, and I checked manually checking the URL manually. I do not have authentication
And I canβt understand if I have a step?
Does anyone have a working example of a django-rest-framework APITestCase create model object test code fragment?
thanks
source share