Python 在django rest框架中使用APITestCase
我遵循了这个准则:Python 在django rest框架中使用APITestCase,python,django,rest,testing,django-rest-framework,Python,Django,Rest,Testing,Django Rest Framework,我遵循了这个准则: 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 a
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)
可在django rest framewok文档中找到:
我用一个字段名称创建了一个模型
,但仍然收到一个“错误请求400错误”。视图和reverse
名称也设置正确,我已经成功地手动测试了查看URL。我没有启用身份验证
不知道我是否错过了一步
有没有人有一个django rest框架APITestCase创建模型对象的工作示例
测试代码片段
谢谢这个GIT
repo有几个工作示例,我能够遵循这些示例并使APITestCase
工作:
您是否尝试过打印响应。错误或响应。数据?@meshy,我只是按照下面的git回购协议来完成工作。谢谢