Using APITestCase with django-rest-framework

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

+6
source share
1 answer

There are several working examples in this GIT repeater that I was able to execute and get APITestCase :

https://github.com/erkarl/django-rest-framework-oauth2-provider-example/blob/master/apps/users/tests.py

+8
source

Source: https://habr.com/ru/post/981723/


All Articles