作者:loy1231998 | 来源:互联网 | 2023-09-16 20:35
测试代码如下:
1 2 3 4 5 6 7 8 9 10
| 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) |
1 2 3 4 5 6 7 8 9 10 11 12 13
| ======================================================================
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,是不是哪里的设置不对?