jeudi 29 janvier 2015

using APITestCase with django-rest-framework

I followed 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 the django-rest-framewok docs here:


http://ift.tt/1zhUdHk


I created a single Model with a single field name, and I am still getting a "bad request 400 error". The view and reverse name is also set up correctly, and I have manually tested viewing the URL with success. I don't have Authentication enabled


And can't figure out if I am missing a step?


Does anyone have a working example of a django-rest-framework APITestCase create model object test code snippet?


Thanks


Aucun commentaire:

Enregistrer un commentaire