Commit 0aeffbe1 by fanxun

三车用例完善1

parent 5c9b154a
__author__ = 'fanxun'
__data__ = "2021-05-17 15:11"
import pytest, allure, xlrd, os
import pytest, allure, xlrd, os, random
import config
from common.utils.getExcelData import get_excelData
from common.tools import request_main
......@@ -24,7 +24,7 @@ class TestCreditScore():
# expectData = inData['expectData']
# res = request_main(url=url, headers=None, method=method, data=req_data, has_token=True)
# assert res['code'] == expectData['code']
#
# #
# @allure.story("获取典型案例视频")
# @allure.link("http://yapi.hikcreate.com/project/31/interface/api/57606")
# @allure.description("/illegal/study/video/typicalCase")
......@@ -49,28 +49,39 @@ class TestCreditScore():
req_data = inData['reqData']
expectData = inData['expectData']
res = request_main(url=url, headers=None, method=method, data=req_data, has_token=True)
assert res['code'] == expectData['code']
@pytest.fixture()
def test_pre_get_paper_illegal_study(self):
"""获取试卷套件"""
url = f"{BMCConfig().host}/paper/getPaper"
method = 'get'
req_data = None
res = request_main(url=url, headers=None, method=method, data=req_data, has_token=True)
topic_lists = res['data']['topicList']
self.browsequestion = {}
self.choosequestion = {}
self.browsequestion['answerId'] = res['data']['answerId']
self.choosequestion['answerId'] = res['data']['answerId']
browsequestion = {}
choosequestion = {}
browsequestion['answerId'] = res['data']['answerId']
choosequestion['answerId'] = res['data']['answerId']
for item in topic_lists:
if item['topicType'] == 2: # 浏览题
self.browsequestion['topicId'] = item['topicId']
self.browsequestion['topicType'] = item['topicType']
elif item['topicType'] == 1:
self.choosequestion['topicId'] = item['topicId']
self.choosequestion['topicType'] = item['topicType']
assert res['code'] == expectData['code']
if item['topicType'] == 2 and len(browsequestion) == 1: # 浏览题
browsequestion['topicId'] = item['topicId']
browsequestion['topicType'] = item['topicType']
elif item['topicType'] == 1 and len(choosequestion) == 1:
choosequestion['topicId'] = item['topicId']
choosequestion['topicType'] = item['topicType']
return browsequestion, choosequestion
@allure.story("提交答案")
@allure.link("http://yapi.hikcreate.com/project/31/interface/api/67473")
@allure.description("/paper/submitAnswer")
@allure.title("{inData[testPoint]}")
@pytest.mark.parametrize("inData", get_excelData(workBook, '三车违法学习', 'submitAnswerIllegalstudy')[0])
def test_submitAnswerIllegalstudy(self, inData):
@pytest.mark.usefixtures('test_pre_get_paper_illegal_study')
@pytest.mark.parametrize("inData", get_excelData(workBook, '三车违法学习', 'submitAnswerIllegalstudy'))
def test_submitAnswerIllegalstudy(self, inData, test_pre_get_paper_illegal_study):
browsequestion, choosequestion = test_pre_get_paper_illegal_study
url = f"{BMCConfig().host}{inData['url']}"
method = inData['method']
req_data = inData['reqData']
......@@ -78,6 +89,32 @@ class TestCreditScore():
req_data['topicId'] = self.browsequestion['topicId']
req_data['topicType'] = self.browsequestion['topicType']
expectData = inData['expectData']
case_num = inData['caseNum']
if case_num == 'submitAnswerIllegalstudy001':
req_data['answerId'] = browsequestion['answerId']
req_data['topicId'] = browsequestion['topicId']
elif case_num == 'submitAnswerIllegalstudy002':
req_data['answerId'] = browsequestion['answerId']
while True:
topic_id = random.randint(1, 100)
if topic_id != browsequestion['topicId']:
req_data['topicId'] = topic_id
break
elif case_num == 'submitAnswerIllegalstudy003':
req_data['topicId'] = browsequestion['topicId']
while True:
answer_id = random.randint(1, 100)
if answer_id != browsequestion['answerId']:
req_data['answerId'] = answer_id
break
elif case_num == 'submitAnswerIllegalstudy004':
req_data['answerId'] = browsequestion['answerId']
req_data['topicId'] = browsequestion['topicId']
req_data['topicType'] = 1
elif case_num == 'submitAnswerIllegalstudy005':
req_data['answerId'] = choosequestion['answerId']
req_data['topicId'] = choosequestion['topicId']
res = request_main(url=url, headers=None, method=method, data=req_data, has_token=True)
assert res['code'] == expectData['code']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment