test_06_internship_manage.py 31.9 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
# -*- coding: utf-8 -*-
# ======================================
# @Software: PyCharm
# @Author  : Shitou ✊
# @Time    : 2023/1/13 11:22
# @FileName: test_06_internship_manage.py
# ======================================
"""
实习管理菜单
"""
import json
import os
import time
import unittest

import requests
from jsonpath import jsonpath

from common.handle_config import conf
from common.handle_excel import Excel
from common.handle_log import HandleLog
from common.handle_path import Internship_manage
from common.myddt import data, ddt
from tools.fixture import SelectData
from tools.handle_token import LoginToken, HrLoginToken, StudentLoginToken


# ==================实习管理菜单相关用例==================

# ====================================================================
#                               报名审核-待审核列表查看--学校
# ====================================================================
@ddt
class Test01SelectApplysubmitList(unittest.TestCase):
    select_apply_submit = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"), "school_select_apply_submit")
    select_apply_submit_case = select_apply_submit.read_excel()  # 查询报名审核Excel

    @classmethod
    def setUpClass(cls):
        # 获取token
        cls.token = LoginToken.login_token()

    @data(*select_apply_submit_case)
    def test01select_wait_list(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()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            # 写入Excel
            self.select_apply_submit.write_excel(row=case["id"] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.select_apply_submit.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.select_apply_submit.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))


# ====================================================================
#                               报名审核-学校端-进行审核
# ====================================================================
@ddt
class Test02Schoolsubmit(unittest.TestCase):
    submit = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"), "school_submit")
    submit_case = submit.read_excel()  # 查询报名审核Excel

    @classmethod
    def setUpClass(cls):
        # 获取token
        cls.token = LoginToken.login_token()

    def setUp(self):
        # ---获取报名审核id---待审核
        select_apply_excel = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"),
                                   "school_select_apply_submit")
        read_apply_excel = select_apply_excel.read_excel_location("C2")
        read_apply_excel_d = select_apply_excel.read_excel_location("E2")  # 读取params
        apply_list = SelectData(str(read_apply_excel), json.loads(read_apply_excel_d))
        apply_json = apply_list.select_list()
        self.applyId = jsonpath(apply_json, "$..id")[0]  # 获取待审核id

    @data(*submit_case)
    def test01submit(self, case):
        if "#formIds#" in case["data"]:
            case["data"] = case["data"].replace("#formIds#", str(self.applyId))  # 待审核id
        # 准备数据
        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"], json=data, headers=herders)
        res = request.json()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            # 写入Excel
            self.submit.write_excel(row=case["id"] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.submit.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.submit.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))


"""
需求改动,无需hr进行审核2023/03/13

# ====================================================================
#                               报名审核-hr端-待审核列表查看(实习申请列表)
# ====================================================================
@ddt
class Test03HrSelectsubmitList(unittest.TestCase):
    select_hr_apply_submit = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"), "hr_select_apply_submit")
    select_hr_apply_submit_case = select_hr_apply_submit.read_excel()  # 查询报名审核Excel

    @classmethod
    def setUpClass(cls):
        # 获取token
        cls.token = HrLoginToken.login_token()

    @data(*select_hr_apply_submit_case)
    def test01select_hr_wait_list(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()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            # 写入Excel
            self.select_hr_apply_submit.write_excel(row=case["id"] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.select_hr_apply_submit.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.select_hr_apply_submit.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))


# ====================================================================
#                               报名审核-hr端-进行审核2022/01/16
# ====================================================================
@ddt
class Test04Hrsubmit(unittest.TestCase):
    hr_submit = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"), "hr_submit")
    hr_submit_case = hr_submit.read_excel()  # 查询报名审核Excel

    @classmethod
    def setUpClass(cls):
        # 获取token
        cls.token = HrLoginToken.login_token()

    def setUp(self):
        # ---获取报名审核id---待审核
        select_hr_apply_excel = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"),
                                      "hr_select_apply_submit")
        read_hr_apply_excel = select_hr_apply_excel.read_excel_location("C2")
        read_hr_apply_excel_d = select_hr_apply_excel.read_excel_location("E2")  # 读取params
        hr_apply_list = SelectData(str(read_hr_apply_excel), json.loads(read_hr_apply_excel_d))
        hr_apply_json = hr_apply_list.select_list()
        self.hr_applyId = jsonpath(hr_apply_json, "$..id")[0]  # 获取待审核id

    @data(*hr_submit_case)
    def test01hrsubmit(self, case):
        if "#formIds#" in case["data"]:
            case["data"] = case["data"].replace("#formIds#", str(self.hr_applyId))  # 待审核id

        # 准备数据
        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"], json=data, headers=herders)
        res = request.json()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            # 写入Excel
            self.hr_submit.write_excel(row=case["id"] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.hr_submit.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.hr_submit.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))
"""


# ====================================================================
#                              学生端---选择实习开始时间
# ====================================================================
@ddt
class Test05StudentIntenship(unittest.TestCase):
    student_start_internship = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"),
                                     "student_start_internshipp")
    student_start_internship_case = student_start_internship.read_excel()  # 学生填写开始时间

    # 登陆前置
    @classmethod
    def setUpClass(cls):
        cls.student_token = StudentLoginToken.login_token()

    def setUp(self):
        # 获取学生端待实习id
        student_select_intership_wait_excle = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"),
                                                    "student_select_intership_wait")
        read_student_intership_excel = student_select_intership_wait_excle.read_excel_location("C2")
        read_student_intership_excel_d = student_select_intership_wait_excle.read_excel_location("E2")  # 读取params
        student_intership_list = SelectData(str(read_student_intership_excel),
                                            json.loads(read_student_intership_excel_d))
        student_intership_json = student_intership_list.student_select_list()  # 正序查找
        self.student_intership_id = jsonpath(student_intership_json, "$..id")[0]  # 获取实习单待实习id

    # 学生开始时间时间选择
    @data(*student_start_internship_case)
    def test01student_start_intenship_time(self, case):
        if "#practice_id#" in case["data"]:
            case["data"] = case["data"].replace("#practice_id#", str(self.student_intership_id))
        # 准备数据
        data = json.loads(case["data"])
        expected = json.loads(case["expected"])
        # 调用接口
        url = conf.get("url", "url_ip") + case["url"]
        headers = {}
        headers["Authorization"] = self.student_token
        request = requests.request(url=url, method=case["method"], json=data, headers=headers)
        res = request.json()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            self.student_start_internship.write_excel(row=case['id'] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.student_start_internship.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.student_start_internship.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))


# ====================================================================
#                              学校端---实习申请审核通过
# ====================================================================
@ddt
class Test06SchoolSelectApply(unittest.TestCase):
    student_internship_applic = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"),
                                      "school_submit_internship_applic")
    student_internship_applic_case = student_internship_applic.read_excel()

    @classmethod
    def setUpClass(cls):
        # 获取token
        cls.token = LoginToken.login_token()

    def setUp(self):
        # ---获取实习申请id---待审核
        select_internship_applic = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"),
                                         "school_select_internship_applic")
        read_internship_applic_excel = select_internship_applic.read_excel_location("C2")
        read_internship_applic_excel_d = select_internship_applic.read_excel_location("E2")  # 读取params
        internship_applic_list = SelectData(str(read_internship_applic_excel),
                                            json.loads(read_internship_applic_excel_d))
        internship_applic_json = internship_applic_list.select_list()
        self.internship_applic = jsonpath(internship_applic_json, "$..id")[0]  # 获取实习申请待审核id

    @data(*student_internship_applic_case)
    def test01submit(self, case):
        if f"#id#" in case["url"]:
            case["url"] = case["url"].replace("#id#", str(self.internship_applic))  # 待审核id

        # 准备数据
        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"], json=data, headers=herders)
        res = request.json()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            # 写入Excel
            self.student_internship_applic.write_excel(row=case["id"] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.student_internship_applic.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.student_internship_applic.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))


# ====================================================================
#                              学生端---写周日志
# ====================================================================
@ddt
class Test07StudentWriteLog(unittest.TestCase):
    student_write_log = Excel(os.path.join(Internship_manage, "test_08_log_marking.xlsx"), "write_log")
    student_write_log_case = student_write_log.read_excel()

    # 登陆前置
    @classmethod
    def setUpClass(cls):
        cls.student_token = StudentLoginToken.login_token()

    def setUp(self):
        """单条用例执行前执行的函数"""
        self.new_time = time.strftime("%Y%m%d_%H:%M:%S")
        # 获取学生端实习中id
        student_select_intership_running_excle = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"),
                                                       "student_select_intership_wait")
        read_student_intership_excel = student_select_intership_running_excle.read_excel_location("C3")
        read_student_intership_excel_d = student_select_intership_running_excle.read_excel_location("E3")  # 读取params
        student_intership_list = SelectData(str(read_student_intership_excel),
                                            json.loads(read_student_intership_excel_d))
        student_intership_json = student_intership_list.student_select_list()  # 正序查找
        self.student_intership_id = jsonpath(student_intership_json, "$..id")[0]  # 获取实习单实习中id

    @data(*student_write_log_case)
    def test01student_write_log(self, case):
        if "#formId#" in case["data"]:
            case["data"] = case["data"].replace("#formId#", str(self.student_intership_id))
        if "#time#" in case["data"]:
            case["data"] = case["data"].replace("#time#", str(self.new_time))
        # 准备数据
        data = json.loads(case["data"])
        expected = json.loads(case["expected"])
        # 调用接口
        url = conf.get("url", "url_ip") + case["url"]
        headers = {}
        headers["Authorization"] = self.student_token
        request = requests.request(url=url, method=case["method"], json=data, headers=headers)
        res = request.json()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            self.student_write_log.write_excel(row=case['id'] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.student_write_log.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.student_write_log.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))


# ====================================================================
#                              教师端---批阅周日志
# ====================================================================
@ddt
class Test08ApproveLog(unittest.TestCase):
    teacher_approve_log = Excel(os.path.join(Internship_manage, "test_08_log_marking.xlsx"), "approve_log")
    teacher_approve_log_case = teacher_approve_log.read_excel()

    # 登陆前置
    @classmethod
    def setUpClass(cls):
        cls.teacher_token = LoginToken.login_token()

    def setUp(self):
        # 获取周日志id
        # ---------------获取日志id
        select_daily_log = Excel(os.path.join(Internship_manage, "test_08_log_marking.xlsx"),
                                 "select_log")
        select_daily_log_excel = select_daily_log.read_excel_location("C2")
        select_daily_log_excel_d = select_daily_log.read_excel_location("E2")  # 读取params
        daily_log_list = SelectData(str(select_daily_log_excel),
                                    json.loads(select_daily_log_excel_d))
        daily_log_json = daily_log_list.select_list()  # 正序查找
        self.daily_ids = jsonpath(daily_log_json, "$..id")[0]  # 获取日志id
        # ---------------获取周志id
        select_weekly_log = Excel(os.path.join(Internship_manage, "test_08_log_marking.xlsx"),
                                  "select_log")
        select_weekly_log_excel = select_weekly_log.read_excel_location("C3")
        select_weekly_log_excel_d = select_weekly_log.read_excel_location("E3")  # 读取params
        weekly_log_list = SelectData(str(select_weekly_log_excel),
                                     json.loads(select_weekly_log_excel_d))
        weekly_log_json = weekly_log_list.select_list()  # 正序查找
        self.weekly_ids = jsonpath(weekly_log_json, "$..id")[0]  # 获取周志id
        # ---------------获取月志id
        select_monthly_log = Excel(os.path.join(Internship_manage, "test_08_log_marking.xlsx"),
                                   "select_log")
        select_monthly_log_excel = select_monthly_log.read_excel_location("C4")
        select_monthly_log_excel_d = select_monthly_log.read_excel_location("E4")  # 读取params
        monthly_log_list = SelectData(str(select_monthly_log_excel),
                                      json.loads(select_monthly_log_excel_d))
        monthly_log_json = monthly_log_list.select_list()  # 正序查找
        self.monthly_ids = jsonpath(monthly_log_json, "$..id")[0]  # 获取月志id

    @data(*teacher_approve_log_case)
    def test01approve_log(self, case):
        if "#daily_ids#" in case["data"]:
            case["data"] = case["data"].replace("#daily_ids#", str(self.daily_ids))  # 日志
        if "#weekly_ids#" in case["data"]:
            case["data"] = case["data"].replace("#weekly_ids#", str(self.weekly_ids))  # 周志
        if "#monthly_ids#" in case["data"]:
            case["data"] = case["data"].replace("#monthly_ids#", str(self.monthly_ids))  # 月志

        # 准备数据
        data = json.loads(case["data"])
        expected = json.loads(case["expected"])
        # 调用接口
        url = conf.get("url", "url_ip") + case["url"]
        headers = {}
        headers["Authorization"] = self.teacher_token
        request = requests.request(url=url, method=case["method"], json=data, headers=headers)
        res = request.json()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            self.teacher_approve_log.write_excel(row=case['id'] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.teacher_approve_log.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.teacher_approve_log.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))


# ====================================================================
#                              学生端---打卡签到
# ====================================================================
@ddt
class Test09Attendance(unittest.TestCase):
    student_attendance = Excel(os.path.join(Internship_manage, "test_08_log_marking.xlsx"), "student_attendance")
    student_attendance_case = student_attendance.read_excel()

    # 登陆前置
    @classmethod
    def setUpClass(cls):
        cls.student_token = StudentLoginToken.login_token()

    def setUp(self):
        # 获取学生端实习中id
        student_select_intership_running_excle = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"),
                                                       "student_select_intership_wait")
        read_student_intership_excel = student_select_intership_running_excle.read_excel_location("C3")
        read_student_intership_excel_d = student_select_intership_running_excle.read_excel_location("E3")  # 读取params
        student_intership_list = SelectData(str(read_student_intership_excel),
                                            json.loads(read_student_intership_excel_d))
        student_intership_json = student_intership_list.student_select_list()  # 正序查找
        self.student_intership_id = jsonpath(student_intership_json, "$..id")[0]  # 获取实习单实习中id

    @data(*student_attendance_case)
    def test01student_attendance(self, case):
        if "#formId#" in case["data"]:
            case["data"] = case["data"].replace("#formId#", str(self.student_intership_id))  # 实习单

        # 准备数据
        data = json.loads(case["data"])
        expected = json.loads(case["expected"])
        # 调用接口
        url = conf.get("url", "url_ip") + case["url"]
        headers = {}
        headers["Authorization"] = self.student_token
        request = requests.request(url=url, method=case["method"], json=data, headers=headers)
        res = request.json()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            self.student_attendance.write_excel(row=case['id'] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.student_attendance.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.student_attendance.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))


# ====================================================================
#                              学生端---请假申请
# ====================================================================

@ddt
class Test10LeaveRecord(unittest.TestCase):
    student_leave_record = Excel(os.path.join(Internship_manage, "test_09_leave_record.xlsx"), "student_leave_record")
    student_leave_record_case = student_leave_record.read_excel()

    # 登陆的前置
    @classmethod
    def setUpClass(cls):
        cls.student_token = StudentLoginToken.login_token()  # 获取学生登陆小程序的token

    def setUp(self):
        """单条用例执行前执行的函数"""
        self.new_time = time.strftime("%Y%m%d_%H:%M:%S")
        # 获取学生端实习中id
        student_select_intership_running_excle = Excel(os.path.join(Internship_manage, "test_07_apply_submit.xlsx"),
                                                       "student_select_intership_wait")
        read_student_intership_excel = student_select_intership_running_excle.read_excel_location("C3")
        read_student_intership_excel_d = student_select_intership_running_excle.read_excel_location("E3")  # 读取params
        student_intership_list = SelectData(str(read_student_intership_excel),
                                            json.loads(read_student_intership_excel_d))
        student_intership_json = student_intership_list.student_select_list()  # 正序查找
        self.student_intership_id = jsonpath(student_intership_json, "$..id")[0]  # 获取实习单实习中id

    @data(*student_leave_record_case)
    def test01student_leave_record(self, case):
        if "#formId#" in case["data"]:
            case["data"] = case["data"].replace("#formId#", str(self.student_intership_id))  # 实习单
        if "#time#" in case["data"]:
            case["data"] = case["data"].replace("#time#", str(self.new_time))  # 请假原因
        # 准备数据
        data = json.loads(case["data"])
        expected = json.loads(case["expected"])
        # 调用接口
        url = conf.get("url", "url_ip") + case["url"]
        headers = {}
        headers["Authorization"] = self.student_token
        request = requests.request(url=url, method=case["method"], json=data, headers=headers)
        res = request.json()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            self.student_leave_record.write_excel(row=case['id'] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.student_leave_record.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.student_leave_record.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))


# ====================================================================
#                              教师端---请假审批--通过
# ====================================================================

@ddt
class Test11TeacherAprove(unittest.TestCase):
    teacher_aprove = Excel(os.path.join(Internship_manage, "test_09_leave_record.xlsx"), "tacher_aprove")
    teacher_aprove_case = teacher_aprove.read_excel()

    # 登陆的前置
    @classmethod
    def setUpClass(cls):
        cls.teacher_token = LoginToken.login_token()  # 获取web教师端的token

    def setUp(self):
        """单条用例执行前执行的函数"""
        self.new_time = time.strftime("%Y%m%d_%H:%M:%S")
        # 获取请假批阅列表的id
        leave_record_excel = Excel(os.path.join(Internship_manage, "test_09_leave_record.xlsx"),
                                   "select_tacher_leave_record")
        read_leave_record = leave_record_excel.read_excel_location("C2")
        read_leave_record_d = leave_record_excel.read_excel_location("E2")
        teacher_leave_record_list = SelectData(str(read_leave_record),
                                               json.loads(read_leave_record_d))
        teacher_leave_record_json = teacher_leave_record_list.select_list()  # 正序查找
        self.leave_record_id = jsonpath(teacher_leave_record_json, "$..id")[0]  # 获取请假审批id

    @data(*teacher_aprove_case)
    def test01teacher_aprove(self, case):

        if "#time#" in case["data"]:
            case["data"] = case["data"].replace("#time#", str(self.new_time))  # 审批通过的回复
        if "{id}" in case["url"]:
            case["url"] = case["url"].replace("{id}", str(self.leave_record_id))
        # 准备数据
        data = json.loads(case["data"])
        expected = json.loads(case["expected"])
        # 调用接口
        url = conf.get("url", "url_ip") + case["url"]
        headers = {}
        headers["Authorization"] = self.teacher_token
        request = requests.request(url=url, method=case["method"], json=data, headers=headers)
        res = request.json()
        print("用例入参:{}".format(data))
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected['msg'], res['msg'])
            self.assertEqual(expected['code'], res['code'])
        except AssertionError as e:
            self.teacher_aprove.write_excel(row=case['id'] + 1, column=7, value="不通过")
            HandleLog.log.error("用例标题{},不通过".format(case['title']))
            HandleLog.log.exception(e)
            raise e
        else:
            self.teacher_aprove.write_excel(row=case["id"] + 1, column=7, value="通过")
            # 将创建使用的数据写入到excel表格中
            self.teacher_aprove.write_excel(row=case["id"] + 1, column=9, value=case["data"])
            HandleLog.log.info("用例{},执行通过".format(case["title"]))