test_05_student_practice.py
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
# ======================================
# @Software: PyCharm
# @Author : Shitou ✊
# @Time : 2023/1/9 16:32
# @FileName: test_05_student_practice.py
# ======================================
"""
学生小程序首页界面"实习界面"
"""
import json
import os
import unittest
import requests
from common.handle_config import conf
from common.handle_excel import Excel
from common.handle_log import HandleLog
from common.myddt import ddt, data
from common.handle_path import Student_practice
from tools.handle_token import StudentLoginToken
@ddt
class Test01SelectAllPractice(unittest.TestCase):
"""学生查看全部实习"""
select_student_practice = Excel(os.path.join(Student_practice, "test_06__practice.xlsx"),
"select_internship_practice")
select_student_practice_case = select_student_practice.read_excel()
@classmethod
def setUpClass(cls):
cls.token = StudentLoginToken.login_token()
@data(*select_student_practice_case)
def test01select_allpatice(self, case):
# 准备数据
data = json.loads(case["data"])
expected = json.loads(case["expected"])
# 调用接口
url = conf.get("url", "url_ip") + case["url"]
herders = {}
herders["Authorization"] = self.token
request = requests.request(url=url, method=case["method"], params=data, headers=herders)
res = request.json()
# 断言
try:
self.assertEqual(expected['msg'], res['msg'])
self.assertEqual(expected['code'], res['code'])
except AssertionError as e:
# 写入Excel
self.select_student_practice.write_excel(row=case["id"] + 1, column=7, value="不通过")
HandleLog.log.error("用例标题{},不通过".format(case['title']))
HandleLog.log.exception(e)
raise e
else:
self.select_student_practice.write_excel(row=case["id"] + 1, column=7, value="通过")
# 将创建使用的数据写入到excel表格中
self.select_student_practice.write_excel(row=case["id"] + 1, column=9, value=case["data"])
HandleLog.log.info("用例{},执行通过".format(case["title"]))