【发布时间】:2019-12-13 22:44:58
【问题描述】:
我一直在尝试使用 Django 的内置测试模块,但没有成功
我尝试过更改我的数据库、在本地运行它等等,但一直遇到同样的错误:
django.db.utils.ProgrammingError: (1064, "您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以了解在第 1 行的“错误”附近使用的正确语法")
下面的test.py模块
from rest_framework.test import APITestCase
from universal.models import *
from django.urls import reverse
# Create your tests here.
class UPCImageSearchTestCase(APITestCase):
def setup(self):
self.url = reverse('UPCImageSearch')
testUpc = Item.object.create(item_upc = '001100110011')
print(self.url)
def test_fetch_success(self):
self.data = {
'upc':''
}
response = self.client.get(self.url,self.data)
self.assertEqual(200,response_status_code)
def test_fetch_failed(self):
self.data = {
'upc':''
}
response = self.client.get(self.url,self.data)
self.assertEqual(500,response_status_code)
【问题讨论】:
-
如发布的那样,
response = self.client(...)和self.assertEqual()行在函数之外,因此对self的引用应该会导致错误。
标签: python django python-3.x django-rest-framework