测试代码如下:
from django.test import TestCase
# Create your tests here.
class SendviewsTestCase(TestCase):
def test_get_data(self):
rep = self.client.post('/data/datamsg/',{'data_name':'测试数据'})
print (rep.content)
# 测试http请求的返回码是否正确
self.assertEqual(rep.status_code,200)
======================================================================
FAIL: test_get_data (dataforpro.tests.SendviewsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/yangtz/developproject/backend/dataforpro/tests.py", line 20, in test_get_data
self.assertEqual(rep.status_code,200)
AssertionError: 404 != 200
----------------------------------------------------------------------
Ran 1 test in 0.017s
FAILED (failures=1)
Destroying test database for alias 'default'...
但是在用浏览器浏览该url时,就能正常返回200,是不是哪里的设置不对?
看你的错误是404,说明访问/data/datamsg/的时候没找到url,要看你的url地址是怎么配的,试试/data/datamsg把后面的/去掉,又或才是你要加上http://localhost之类的