#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2022/12/8 21:52
# @Author  : Shitou
# @FileName: run.py
# @Software: PyCharm

import unittest
from unittestreport import TestRunner
from common.handle_path import TestCase_Path, Report_Path
from common.handle_config import conf
from testcase.test_01_login import TestLogin
from testcase.test_02_system_management import Test01Department, Test02Specialty, Test03Year
from testcase.test_03_teaching_affairs import Test01Teacher, Test02Class, Test03Course, Test04Student
from testcase.test_04_Internship_preparation import Test01InternshipPlan



"""
执行所有用例
"""
# # 创建测试套件
# suite = unittest.TestSuite()
# # 加载用例
# # ---创建加载器
# load = unittest.TestLoader()
# # ---用例放到加载器
# suite.addTest(load.discover(TestCase_Path))
"""
执行单独模块用例
"""
a = unittest.TestLoader().loadTestsFromTestCase(Test01InternshipPlan)
# b = unittest.TestLoader().loadTestsFromTestCase(Test03Year)
suite = unittest.TestSuite([a])

# # 运行
runner = TestRunner(suite=suite,
                    filename=conf.get("report", "filename"),
                    report_dir=Report_Path,
                    title=conf.get("report", "title"),
                    tester=conf.get("report", "tester"),
                    desc=conf.get("report", "desc"),
                    templates=conf.getint("report", "templates")
                    )
runner.run()
# 执行失败重新运行机制
# runner.rerun_run(count=3, interval=0.2)

"""
发送钉钉
"""
# Webhook = "https://oapi.dingtalk.com/robot/send?access_token=cb3e40995683f06c5be06074e0cf617f2ea208156e3b4bf6247b56a212b8b7c3"
# Webhook = "https://oapi.dingtalk.com/robot/send?access_token=054f620071c74d94c10ad556743aa5ff0600a2953bbce5529ca057f75ad2423e"  # 优秀学乐业钉钉群
# runner.dingtalk_notice(url=Webhook,
#                        key="石头测试",  # 传入钉钉设置的对应关键字
#                        atMobiles=["17301249973"],  # 发送通知钉钉中要@人的手机号列表
#                        isatall=False,  # 是否@所有人,默认为False,设为True则会@所有人
#                        except_info=True  # 是否发送未通过用例的详细信息,默认为False
#                        )
"""
发送邮件
"""
# runner.send_email(host="smtp.qq.com",
#                   port=465,
#                   user="shishut@foxmail.com",
#                   password="uwgmbvzjfscqbeeh",
#                   to_addrs=["shishut@workai.com.cn"]
#                   # to_addrs=["shishut@workai.com.cn", "wangf@workai.com.cn"]
#                   )