我正在使用Python进行django-rest项目。我想编写测试来检查我是否在localhost:8000 / swagger和localhost:8000 / redoc上从招摇和重做中获得了200条响应,而我对此的想法不为零。这是用于测试我的API的有效测试,并且工作正常,我想知道我可以添加的swagger / redoc测试。我试图查找并实施一些测试,但是由于我不熟悉这一切而感到迷茫(我拥有数据科学家的背景)。有指导吗?
我正在使用Python 3.7
from rest_framework.test import APITestCase
from .config import SQL_CONF
class MegaTestCase(APITestCase):
def test_basic(self):
indices = list(SQL_CONF['INDICES'])
request = {
"indices": indices,
"filters": {
"nom": [1],
"dates": {"startDate": "2018-03-01", "endDate": "2019-03-01"},
"cDates": {"startDate": "2017-03-01", "endDate": "2018-03-01"},
"p": None,
"s": None,
"l": None
},
"fields": {
"name": True,
"value": True,
"unit": True,
"pr": True,
"di": True
},
"groupBy": ["l"]
}
response = self.client.post("/mega", request)
self.assertEqual(200, response.status_code)
self.assertNotEqual(response.data, [])
m_calculated = 0
m = 0
indices_m_list = ["gMaRapp", "boRaRapp",
"wMaRaRapp", "inMaRaRapp", "RFARaRapp"]
for indice in response.data['data'][0]["indices"]:
if indice["name"] in indices_m_list:
m_calculated += indice["value"]
elif indice["name"] == "gMaRapp":
m = indice["value"]
self.assertAlmostEqual(m, ma_calculated, delta=0.001)