Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在django rest框架中使用APITestCase_Python_Django_Rest_Testing_Django Rest Framework - Fatal编程技术网

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回购协议来完成工作。谢谢