Ejemplo n.º 1
0
def run_case(all_case, result_path=setting.TEST_REPORT):
    """执行所有的测试用例"""

    # 初始化接口测试数据
    # test_data.init_data()

    now = time.strftime("%Y-%m-%d %H_%M_%S")
    filename = result_path + '/' + now + 'result.html'
    fp = open(filename, 'wb')
    runner = HTMLTestRunner(stream=fp,
                            title='电子合同系统接口自动化测试报告',
                            description='环境:windows 10 浏览器:chrome',
                            tester='李雪殿')
    runner.run(all_case)
    fp.close()
    report = new_report(setting.TEST_REPORT)  #调用模块生成最新的报告
    # send_mail(report) #调用发送邮件模块
    # 判断邮件发送的开关
    if on_off == 'on':
        m = SendEmail(
            username='******',
            passwd='DWSBWWENHZPEUZKB',
            recv=['*****@*****.**'],
            title='接口自动化测试报告',
            content='接口自动化测试报告',
            file=report,  # 获取测试报告路径
            ssl=True,
        )
        m.send_email()
    else:
        print("邮件发送开关配置关闭,请打开开关后可正常自动发送测试报告")
Ejemplo n.º 2
0
def excetestcase():
    requests = handler((dict(request.args)))  # 获取所有接收到的参数。
    error = None
    data = None
    # 反序列化
    try:
        schema = model.TestcaseinputSchema()
        data = schema.load(requests)
        data = schema.dump(data)
        # print(data)
    except ValidationError as err:
        error = err.messages
        # print(error)
    returnres = {"state": 200, "msg": "succsuful", "result": ""}
    if error != None:
        returnres['msg'] = error
        return jsonify(returnres)
    else:
        moud, clas = dynamicimport(data['filename'], data['classname'])
        # 构造测试集
        suite = unittest.TestSuite()
        suite.addTest(clas(data['funcname']))
        # 执行测试,生成测试报告
        now = time.strftime("%Y-%m-%d %H_%M_%S")
        filename = setting.TEST_REPORTDIR + '/' + now + '_%s_result.html' % (data['testid'])
        fp = open(filename, 'wb')
        runner = HTMLTestRunner(stream=fp, title='发布会系统接口自动化测试报告',
                                description='环境:windows 10 浏览器:chrome',
                                tester='-零')
        runner.run(suite)
        fp.close()
        report = new_report(setting.TEST_REPORTDIR)  # 调用模块生成最新的报告
        return jsonify(returnres)
Ejemplo n.º 3
0
def create_steptask(data):
    print("celery接收参数:", data)
    Conn = ConnConfig()
    with Conn.engine.connect() as db:
        sql = "select moudle_name,test_filename,test_classname from " + 'moudletable where id = %d;' % (
            data['moudleid'])
        # print(sql)
        result = db.execute(sql)
        result = result.fetchall()
        if len(result[0][1].split(',')) == 1:
            moud, clas = dynamicimport(result[0][1], result[0][2])
            # 构造测试集
            suite = unittest.TestSuite()
            for name, function in inspect.getmembers(clas, inspect.isfunction):
                if 'test' in name:
                    suite.addTest(clas(name))
        else:
            suite = unittest.TestSuite()
            moud = importlib.import_module('testcase.%s' % result[0][1],
                                           package='testcase')
            for name, class_ in inspect.getmembers(moud, inspect.isclass):
                if name in result[0][2].split(','):
                    for name, method in inspect.getmembers(
                            class_, inspect.isfunction):
                        if 'test' in name:
                            print(name)
                            suite.addTest(class_(name))
        # 执行测试,生成测试报告
        now = time.strftime("%Y-%m-%d %H_%M_%S")
        filename = setting.TEST_REPORTDIR + '/' + now + '_%s_result.html' % (
            data['moudleid'])
        fp = open(filename, 'wb')
        runner = HTMLTestRunner(stream=fp,
                                title='测试报告',
                                description='环境:windows 10 浏览器:chrome',
                                tester='-')
        runner.run(suite)
        fp.close()
        new_report(setting.TEST_REPORTDIR)  # 调用模块生成最新的报告
        task_id = create_steptask.apply_async(
            ([data]), countdown=int(data['date3']) * 60)
Ejemplo n.º 4
0
def newexcetestcase():
    # ID
    requests = handler((dict(request.args)))  # 获取所有接收到的参数。
    error = None
    data = None
    # 反序列化
    try:
        schema = model.TestreportlistSchema()
        data = schema.load(requests)
        data = schema.dump(data)
        # print(data)
    except ValidationError as err:
        error = err.messages
        # print(error)
        # 获取数据
    returnres = {"state": 200, "msg": "succsuful", "result": ""}
    reslist = []
    if error != None:
        returnres['msg'] = error
        return jsonify(returnres)
    else:
        if 'testid' in data:
            Conn = ConnConfig()
            with Conn.engine.connect() as db:
                sql = "select test_filename,test_classname,test_funcname from " + 'casetable where test_id = "%s";' % (
                data['testid'])
                print(sql)
                result = db.execute(sql)
            result = result.fetchall()
            if len(result):
                print("执行测试用例的脚本绑定!")
                moud, clas = dynamicimport(result[0][0], result[0][1])
                # 构造测试集
                suite = unittest.TestSuite()
                suite.addTest(clas(result[0][2]))
                # 执行测试,生成测试报告
                now = time.strftime("%Y-%m-%d %H_%M_%S")
                filename = setting.TEST_REPORTDIR + '/' + now + '_%s_result.html' % (data['testid'])
                fp = open(filename, 'wb')
                runner = HTMLTestRunner(stream=fp, title='测试报告',
                                        description='环境:windows 10 浏览器:chrome',
                                        tester='-')
                runner.run(suite)
                fp.close()
                report = new_report(setting.TEST_REPORTDIR)  # 调用模块生成最新的报告
            else:
                print("无测试用例的脚本绑定!")
            returnres['result'] = reslist
        else:
            returnres['result'] = reslist
        return jsonify(returnres)
Ejemplo n.º 5
0
def send_mail(file_new):
    """
    定义发送邮件
    :param file_new:
    :return: 成功:打印发送邮箱成功;失败:返回失败信息
    """
    f = open(file_new, 'rb')
    mail_body = f.read()
    f.close()
    # 发送附件
    con = configparser.ConfigParser()
    con.read(setting.TEST_CONFIG, encoding='utf-8')
    report = new_report(setting.TEST_REPORT)
    sendfile = open(report, 'rb').read()
    # --------- 读取config.ini配置文件 ---------------
    HOST = con.get("user", "HOST_SERVER")
    SENDER = con.get("user", "FROM")
    RECEIVER = con.get("user", "TO")
    USER = con.get("user", "user")
    PWD = con.get("user", "password")
    SUBJECT = con.get("user", "SUBJECT")

    att = MIMEText(sendfile, 'base64', 'utf-8')
    att["Content-Type"] = 'application/octet-stream'
    att.add_header(
        "Content-Disposition",
        "attachment",
        filename=(
            "gbk",
            "",
            report))

    msg = MIMEMultipart('related')
    msg.attach(att)
    msgtext = MIMEText(mail_body, 'html', 'utf-8')
    msg.attach(msgtext)
    msg['Subject'] = SUBJECT
    msg['from'] = SENDER
    msg['to'] = RECEIVER

    try:
        server = smtplib.SMTP(HOST)
        server.connect(HOST)
        server.starttls()
        server.login(USER, PWD)
        server.sendmail(SENDER, RECEIVER, msg.as_string())
        server.quit()
        print("邮件发送成功!")
    except Exception as e:
        print("失败: " + str(e))
Ejemplo n.º 6
0
def run_case(all_case, result_path=setting.TEST_REPORT):
    """执行所有的测试用例"""

    # 初始化接口测试数据
    # test_data.init_data()

    now = time.strftime("%Y-%m-%d %H_%M_%S")
    filename = result_path + '/' + now + 'result.html'
    fp = open(filename, 'wb')
    runner = HTMLTestRunner(stream=fp,
                            title='发布会系统接口自动化测试报告',
                            description='环境:windows 7 浏览器:chrome',
                            tester='Jason')
    runner.run(all_case)
    fp.close()
    report = new_report(setting.TEST_REPORT)  #调用模块生成最新的报告
Ejemplo n.º 7
0
def run_case(all_case, result_path=setting.TEST_REPORT):
    '''执行所有测试用例'''

    # 初始化接口测试数据
    # test_data.init_data()

    now = time.strftime('%Y-%m-%d %H_%M_%S')
    filename = result_path + '/' + now + 'result.html'
    fp = open(filename, 'wb')
    runner = HTMLTestRunner(stream=fp,
                            title='融合平台系统接口自动化测试报告',
                            description='环境:win10 浏览器:chrome',
                            tester='sheng')
    runner.run(all_case)
    fp.close()
    report = new_report(setting.TEST_REPORT)  # 调试模块生成最新的报告
def run_case(all_case,result_path=setting.TEST_REPORT):
    """执行所有的测试用例"""

    # 初始化接口测试数据
    #test_data.init_data()

    now = time.strftime("%Y-%m-%d %H_%M_%S")
    filename =  result_path + '/' + now + 'result.html'
    fp = open(filename,'wb')
    runner = HTMLTestRunner(stream=fp, title='成熟度问卷调查测试报告',description='Version 1测试结果')
    runner.run(all_case)
    fp.close()
    report = new_report(setting.TEST_REPORT) #调用模块生成最新的报告
    con = configparser.ConfigParser()
    con.read(setting.TEST_CONFIG, encoding ='utf-8')
    # --------- 读取config.ini配置文件 ---------------
    HOST = con.get("user","HOST_SERVER")
    SENDER = con.get("user","FROM")
    RECEIVER = con.get("user","TO")
    USER = con.get("user","user")
    PWD = con.get("user","password")
    SUBJECT = con.get("user","SUBJECT")
    smtp = SMTP(user=SENDER, password=PWD, host=HOST)
    smtp.sender(to=RECEIVER, attachments= filename)