Exemple #1
0
 def post(self):
     user_id = session.get('user_id')
     name, description = request_get_values('name', 'description')
     FrontLogs('开始添加测试用例分组 name: %s ' % name).add_to_front_log()
     case_group = CaseGroup(name, description, user_id)
     db.session.add(case_group)
     db.session.commit()
     FrontLogs('开始添加测试用例分组 name: %s 成功' % name).add_to_front_log()
     # app.logger.info('message:insert into case_group success, name: %s' % name)
     return redirect(url_for('case_group_blueprint.case_group_list'))
Exemple #2
0
 def get(self, testcase_scene_id):
     testcase_scene = TestCaseScene.query.get(testcase_scene_id)
     page = request.args.get('page')
     if testcase_scene.is_model == 0 or testcase_scene.is_model is None:
         testcase_scene.is_model = 1
         FrontLogs('设置测试场景 name: %s 作为模板成功' % testcase_scene.name).add_to_front_log()
     else:
         testcase_scene.is_model = 0
         FrontLogs('取消设置测试场景 name: %s 作为模板成功' % testcase_scene.name).add_to_front_log()
     db.session.commit()
     return redirect(url_for('testcase_scene_blueprint.testcase_scene_testcase_list', page=page))
Exemple #3
0
 def get(self, id=-1):
     testcase = TestCases.query.get(id)
     page = request.args.get('page')
     if testcase.is_model == 0:
         testcase.is_model = 1
         FrontLogs('设置测试用例 name: %s 为模板成功' %
                   testcase.name).add_to_front_log()
     else:
         testcase.is_model = 0
         FrontLogs('取消设置测试用例 name: %s 为模板成功' %
                   testcase.name).add_to_front_log()
     db.session.commit()
     return redirect(url_for('testcase_blueprint.test_case_list',
                             page=page))
Exemple #4
0
    def get(self):
        scene_page, testcase_scene_id = request_get_values('scene_page', 'testcase_scene_id')
        testcase_scene = TestCaseScene.query.get(testcase_scene_id)
        testcases = TestCases.query.join(TestCaseScene, TestCases.testcase_scene_id == TestCaseScene.id).\
            filter(TestCases.testcase_scene_id == testcase_scene_id).all()

        if len(testcases) > 0:
            for testcase in testcases:
                db.session.delete(testcase)
                FrontLogs('删除测试场景 id: %s  关联的测试用例名称 %s' % (testcase_scene_id, testcase.name)).add_to_front_log()
        db.session.delete(testcase_scene)
        db.session.commit()
        FrontLogs('删除测试场景 id: %s' % testcase_scene_id).add_to_front_log()
        return redirect(url_for('testcase_scene_blueprint.testcase_scene_testcase_list', page=scene_page))
Exemple #5
0
 def post(self):
     user_id = session.get('user_id')
     name, value, description = request_get_values('name', 'value',
                                                   'description')
     FrontLogs('开始添加全局变量 name: %s' % name).add_to_front_log()
     variable = Variables(name,
                          value,
                          description=description,
                          user_id=user_id)
     db.session.add(variable)
     db.session.commit()
     FrontLogs('添加全局变量 name: %s 成功' % name).add_to_front_log()
     # app.logger.info('message:insert into variables success, name: %s' % name)
     return redirect(url_for('variables_blueprint.variable_list'))
Exemple #6
0
    def get(self, id=-1):
        testcase_id = request.args.get('id', id)
        user_id = session.get('user_id')
        print('testcase_id:', testcase_id)
        testcase = TestCases.query.get(testcase_id)
        if testcase.old_sql_id:
            old_mysql = Mysql.query.get(testcase.old_sql_id)
            old_mysql.name = AnalysisParams().analysis_params(old_mysql.name)
        else:
            old_mysql = ''
        if testcase.new_sql_id:
            new_mysql = Mysql.query.get(testcase.new_sql_id)
            new_mysql.name = AnalysisParams().analysis_params(new_mysql.name)
        else:
            new_mysql = ''
        case_groups = CaseGroup.query.all()
        case_group_id_before = testcase.group_id
        request_headers_id_before = testcase.request_headers_id
        request_headerses = RequestHeaders.query.all()
        FrontLogs('查看测试用例 name: %s ' % testcase.name).add_to_front_log()

        return render_template(
            'test_case/test_case_look.html',
            item=testcase,
            case_groups=case_groups,
            request_headers_id_before=request_headers_id_before,
            case_group_id_before=case_group_id_before,
            request_headerses=request_headerses,
            old_mysql=old_mysql,
            new_mysql=new_mysql)
Exemple #7
0
 def get(self, id=-1):
     user_id = session.get('user_id')
     user = User.query.get(user_id)
     page = request_get_values('page')
     mysqls = Mysql.query.filter(Mysql.user_id == user_id).all()
     for mysql in mysqls:
         mysql.name = AnalysisParams().analysis_params(mysql.name)
     testcase_scene_id = request.args.get('testcase_scene_id', None)
     scene_page = request.args.get('scene_page')
     print('UpdateTestCase get:testcase_scene_id ', testcase_scene_id)
     testcase = TestCases.query.filter(TestCases.id == id).first()
     print('testcase.group_id:', testcase.group_id)
     # 获取测试用例分组的列表
     case_groups = user.user_case_groups
     case_group_id_before = testcase.group_id
     request_headers_id_before = testcase.request_headers_id
     request_headerses = user.user_request_headers
     print('testcase:', testcase)
     print('case_groups :', case_groups)
     print('request_headerses:', request_headerses)
     FrontLogs('进入编辑测试用例 id: %s 页面' % id).add_to_front_log()
     return render_template(
         'test_case/test_case_search.html',
         item=testcase,
         case_groups=case_groups,
         request_headers_id_before=request_headers_id_before,
         case_group_id_before=case_group_id_before,
         request_headerses=request_headerses,
         testcase_scene_id=testcase_scene_id,
         scene_page=scene_page,
         page=page,
         mysqls=mysqls)
Exemple #8
0
    def post(self):

        page, job_id, name, description, triggers, cron, is_start, mail_id= request_get_values(
            'page', 'job_id', 'name', 'description', 'triggers', 'cron', 'is_start', 'email')
        testcases = request.form.getlist('testcase')
        testcase_scenes = request.form.getlist('testcase_scene')
        print('JobUpdate post:', testcases, testcase_scenes, is_start)
        if len(testcases) > 0:
            testcases = ','.join(testcases)+','
        else:
            testcases = ''
        if len(testcase_scenes) > 0:
            testcase_scenes = ','.join(testcase_scenes)+','
        else:
            testcase_scenes = ''
        job = Job.query.get(job_id)
        old_cron = job.cron
        job.name = name
        job.testcases = testcases
        job.testcase_scenes = testcase_scenes
        job.description = description
        job.triggers = triggers
        job.cron = cron
        job.is_start = is_start
        job.mail_id = mail_id
        db.session.commit()
        print('old_cron cron:', old_cron, cron)
        if old_cron == cron:
            scheduler_job(job)
        else:
            scheduler_job(job, cron_change=1)
        FrontLogs('编辑任务 name 成功: %s ' % name).add_to_front_log()
        return redirect(url_for('job_blueprint.job_list', page=page))
Exemple #9
0
 def get(self):
     mysql_id = request_get_values('mysql_id')
     mysql = Mysql.query.get(mysql_id)
     db.session.delete(mysql)
     db.session.commit()
     FrontLogs('删除mysql配置 name: %s 成功' % mysql.name).add_to_front_log()
     return redirect(url_for('mysql_blueprint.mysql_list'))
Exemple #10
0
    def get(self):
        user_id = session.get('user_id')
        user = User.query.get(user_id)
        print('user_id:', user_id)
        FrontLogs('进入测试用例执行页面').add_to_front_log()
        case_groups = user.user_case_groups
        case_groups_new = []
        for case_group in case_groups:
            case_group_NullObject = NullObject()
            case_group_NullObject.name = case_group.name
            testcase_list = []
            testcases = TestCases.query.join(
                CaseGroup, CaseGroup.id == TestCases.group_id).filter(
                    TestCases.testcase_scene_id.is_(None),
                    TestCases.group_id == case_group.id,
                    TestCases.user_id == user_id).all()
            print(' %s testcases_:' % case_group, testcases)
            for testcase in testcases:
                testcase_NullObject = NullObject()
                testcase_NullObject.id = testcase.id
                testcase_NullObject.name = testcase.name
                testcase_NullObject.is_testcase_scene = 0
                testcase_list.append(testcase_NullObject)
            try:
                case_group_scene = TestCaseScene.query.join(
                    CaseGroup, CaseGroup.id == TestCaseScene.group_id).filter(
                        TestCaseScene.user_id == user_id,
                        CaseGroup.name == case_group.name).all()
                for testcase_scene in case_group_scene:
                    testcase_scene_NullObject = NullObject()
                    testcase_scene_NullObject.id = testcase_scene.id
                    testcase_scene_NullObject.name = testcase_scene.name
                    testcase_scene_NullObject.is_testcase_scene = 1
                    testcase_list.append(testcase_scene_NullObject)
            except KeyError:
                pass

            case_group_NullObject.testcase_list = testcase_list
            case_groups_new.append(case_group_NullObject)
            print('testcase_list: ', case_group_NullObject.name, testcase_list)

        no_case_group = type('no_case_group', (object, ), dict(a=-1))
        case_groups_new.append(no_case_group)
        no_case_group.testcases = TestCases.query.filter(
            TestCases.group_id.in_([None, '']),
            TestCases.testcase_scene_id.is_(None),
            TestCases.user_id == user_id).all()
        no_case_group.name = "<span style='color: blue'>未分组测试用例</span>"
        print('no_case_group testcases :', no_case_group.testcases)

        no_scene_group = type('testcase_scene_group', (object, ), dict(a=-1))
        case_groups_new.append(no_scene_group)
        no_scene_group.testcases = TestCaseScene.query.filter(
            TestCaseScene.group_id.is_(None),
            TestCaseScene.user_id == user_id).all()
        no_scene_group.name = "<span style='color: blue'>未分组测试场景</span>"
        print('no_scene_group.testcases :', no_scene_group.testcases)

        return render_template('test_case_request/test_case_request.html',
                               case_groups=case_groups_new)
Exemple #11
0
 def get(self):
     user_id = session.get('user_id')
     user = User.query.get(user_id)
     page= request_get_values('page')
     case_groups = user.user_case_groups
     FrontLogs('进入测试场景添加页面').add_to_front_log()
     return render_template('testcase_scene/testcase_scene_add.html', case_groups=case_groups, page=page)
Exemple #12
0
    def get(self):
        page, testcase_id = request_get_values('page', 'testcase_id')
        testcase_self = TestCases.query.get(testcase_id)

        timestr = str(datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
        name = testcase_self.name + timestr
        db.session.add(
            TestCases(
                name,
                testcase_self.url,
                testcase_self.data,
                testcase_self.regist_variable,
                testcase_self.regular,
                testcase_self.method,
                testcase_self.group_id,
                testcase_self.request_headers_id,
                hope_result=testcase_self.hope_result,
                user_id=testcase_self.user_id,
                old_sql=testcase_self.old_sql,
                new_sql=testcase_self.old_sql,
                old_sql_regist_variable=testcase_self.old_sql_regist_variable,
                new_sql_regist_variable=testcase_self.new_sql_regist_variable,
                old_sql_hope_result=testcase_self.old_sql_hope_result,
                new_sql_hope_result=testcase_self.new_sql_hope_result,
                old_sql_id=testcase_self.old_sql_id,
                new_sql_id=testcase_self.new_sql_id))
        db.session.commit()
        FrontLogs('复制测试用例 name: %s 为模板成功' %
                  testcase_self.name).add_to_front_log()
        return redirect(url_for('testcase_blueprint.test_case_list',
                                page=page))
Exemple #13
0
    def post(self):

        testcase_id, case_group_id, testcase_add_run, testcase_update_run \
            = request_get_values('testcase_id', 'case_group_id', 'testcase_add_run', 'testcase_update_run')
        testcase = TestCases.query.get(testcase_id)
        print('TestCaseRunForm: ', request.form)
        if testcase_update_run:
            testcase.name, testcase.url, testcase.data, testcase.method \
                = request_get_values('name', 'url', 'data', 'method')
        if testcase_add_run:
            testcase = NullObject()
            testcase.name, testcase.url, testcase.data, testcase.method, request_headers_id, \
            testcase.regist_variable, testcase.regular \
                = request_get_values('name', 'url', 'data', 'method', 'request_headers', 'regist_variable', 'regular')
            testcase.testcase_request_header = RequestHeaders.query.get(
                request_headers_id)
        testcase_results = []
        testcase_result, regist_variable_value = to_execute_testcase(testcase)
        # print('regist_variable_value', regist_variable_value)
        testcase_results.extend([
            '【%s】' % testcase.name, testcase_result, '【正则匹配的值】',
            regist_variable_value
        ])
        testcase_results_html = '<br>'.join(testcase_results)
        # print('TestCaseRun testcase_results_html', testcase_results_html.encode('utf-8').decode('gbk'))
        FrontLogs('执行测试用例 name: %s ' % testcase.name).add_to_front_log()
        return json.dumps({'testcase_result': testcase_results_html})
Exemple #14
0
 def get(self, id=-1):
     id = request.args.get('request_headers_id', id)
     # 如果有request_headers_id的get请求参数,那么用此参数作为id,否则就用id
     FrontLogs('进入修改请求头部 id: %s 页面' % id).add_to_front_log()
     request_headers = RequestHeaders.query.get(id)
     return render_template('request_headers/request_headers_update.html',
                            item=request_headers)
Exemple #15
0
    def post(self):
        testcase_time_id = request.args.get('testcase_time_id')
        # 生成测试报告
        get_report(testcase_time_id)
        testcase_scene_ids, testcase_scene_list, testcase_scene_testcases_after_list, testcase_results, testcase_time, items = get_testcase_scene_message(
            testcase_time_id)
        for testcase_scene_id in testcase_scene_ids:
            testcase_scene = TestCaseScene.query.get(testcase_scene_id)
            testcase_scene_list.append(testcase_scene)
            testcase_scene_testcases = []
            for testcase_scene_testcase in testcase_scene_testcases_after_list:
                if testcase_scene_testcase.scene_id == testcase_scene.id:
                    testcase_scene_testcases.append(testcase_scene_testcase)
                testcase_scene.test_cases = testcase_scene_testcases
        allocation = EnvMessage(testcase_results, testcase_time_id,
                                testcase_time, testcase_scene_list)
        print('allocation:', allocation.fail_sum)
        time_message = TimeMessage(
            allocation.test_name, allocation.zdbm_version, allocation.test_pl,
            allocation.test_net, allocation.title_name, allocation.fail_sum,
            allocation.test_sum, allocation.test_success,
            allocation.time_strftime, allocation.score, testcase_time_id)
        db.session.add(time_message)
        db.session.commit()

        FrontLogs('进入测试报告页面 报告id: %s' % testcase_time_id).add_to_front_log()
        # return items, Allocation
        return render_template("testcase_report/testcase_report.html",
                               items=items,
                               allocation=allocation,
                               testcase_scene_list=testcase_scene_list)
Exemple #16
0
 def post(self, id=-1):
     name, description = request_get_values('name', 'description')
     case_group_update_sql = 'update case_group set name=?,description=? where id=?'
     cdb().opeat_db(case_group_update_sql, (name, description, id))
     FrontLogs('编辑测试用例分组 name:%s 成功' % name).add_to_front_log()
     # app.logger.info('message:update case_group success, name: %s' % name)
     return redirect(url_for('case_group_blueprint.case_group_list'))
Exemple #17
0
 def post(self):
     user_id = session.get('user_id')
     page, name, group_id, description = request_get_values('page', 'name', 'case_group', 'description')
     testcase_scene = TestCaseScene(name, group_id, description, user_id=user_id)
     db.session.add(testcase_scene)
     db.session.commit()
     FrontLogs('添加测试场景 name: %s 成功' % testcase_scene.name).add_to_front_log()
     return redirect(url_for('testcase_scene_blueprint.testcase_scene_testcase_list', page=page))
Exemple #18
0
 def post(self, id=-1):
     name, value, description = request_get_values('name', 'value',
                                                   'description')
     variable_update_sql = 'update variables set name=?,value=?,description=? where id=?'
     cdb().opeat_db(variable_update_sql, (name, value, description, id))
     # app.logger.info('message:update variables success, name: %s' % name)
     FrontLogs('编辑全局变量 name: %s 成功' % name).add_to_front_log()
     return redirect(url_for('variables_blueprint.variable_list'))
Exemple #19
0
 def get(self, id=-1):
     FrontLogs('进入编辑测试用例分组 id:%s 页面' % id).add_to_front_log()
     id = request.args.get('case_group_id',
                           id)  # 如果有case_group_id的get请求参数,那么用此参数作为id,否则就用id
     case_group = CaseGroup.query.get(id)
     print('case_group:', case_group)
     return render_template('case_group/case_group_update.html',
                            item=case_group)
Exemple #20
0
    def get(self, id=-1):

        delete_request_headers_sql = 'delete from request_headers where id=?'
        cdb().opeat_db(delete_request_headers_sql, (id, ))
        FrontLogs('删除请求头部 id: %s 成功' % id).add_to_front_log()
        # app.logger.info('message:delete request_headers success, id: %s' % id)
        return redirect(
            url_for('request_headers_blueprint.request_headers_list'))
Exemple #21
0
 def post(self):
     user_id = session.get('user_id')
     name, subject, to_user_list, email_method = request_get_values(
         'name', 'subject', 'to_user_list', 'email_method')
     mail = Mail(name, subject, user_id, to_user_list, email_method)
     db.session.add(mail)
     db.session.commit()
     FrontLogs('添加邮件配置 name: %s 成功' % name).add_to_front_log()
     return redirect(url_for('mail_blueprint.mail_list'))
Exemple #22
0
 def post(self):
     username, password = request_get_values('username', 'password')
     user = User(username, password)
     db.session.add(user)
     db.session.commit()
     new_user = User.query.filter(User.username == username).first().id
     add_pre_data_go(new_user)
     FrontLogs('添加用户 name : %s 成功 ' % username).add_to_front_log()
     return redirect(url_for('login_blueprint.login'))
Exemple #23
0
    def post(self):
        page= request_get_values('page')
        testcase_scene_id = request.args.get('testcase_scene_id')
        testcase_scene = TestCaseScene.query.get(testcase_scene_id)
        testcase_scene.name, testcase_scene.group_id, testcase_scene.description = request_get_values('name', 'case_group', 'description')

        db.session.commit()
        FrontLogs('编辑测试场景 name: %s 成功' % testcase_scene.name).add_to_front_log()
        return redirect(url_for('testcase_scene_blueprint.testcase_scene_testcase_list', page=page))
Exemple #24
0
 def post(self):
     user_id = session.get('user_id')
     name, ip, port, user, password, db_name, description = request_get_values(
         'name', 'ip', 'port', 'user', 'password', 'db_name', 'description')
     mysql = Mysql(name, ip, port, user, password, db_name, description,
                   user_id)
     db.session.add(mysql)
     db.session.commit()
     FrontLogs('添加mysql配置 name: %s 成功' % name).add_to_front_log()
     return redirect(url_for('mysql_blueprint.mysql_list'))
Exemple #25
0
 def get(self):
     scene_page, testcase_scene_id = request_get_values('scene_page', 'testcase_scene_id')
     testcase_scene = TestCaseScene.query.get(testcase_scene_id)
     timestr = str(datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
     name = testcase_scene.name + timestr
     testcase_scene_copy = TestCaseScene(name, description=testcase_scene.description, user_id=testcase_scene.user_id)
     db.session.add(testcase_scene_copy)
     db.session.commit()
     FrontLogs('复制测试场景 name: %s 成功' % testcase_scene.name).add_to_front_log()
     return redirect(url_for('testcase_scene_blueprint.testcase_scene_testcase_list', page=scene_page))
Exemple #26
0
 def post(self):
     user_id =session.get('user_id')
     testcases, testcase_scenes, description = request_get_values('testcases', 'testcase_scenes', 'description')
     print('JobAdd: ', testcases, type(testcases), eval(testcases), type(eval(testcases)), testcase_scenes)
     job = Job(testcases, testcase_scenes, description, user_id)
     db.session.add(job)
     db.session.commit()
     FrontLogs('添加任务 name 成功: %s ' % job.name).add_to_front_log()
     # app.logger.info('message:insert into SchedulerJobs success, name: %s' % name)
     return json.dumps({"job_id": str(job.id)})
Exemple #27
0
 def get(self):
     user_id = session.get('user_id')
     user = User.query.get(user_id)
     page= request_get_values('page')
     print('TestCaseSceneUpdate page: ', page)
     case_groups = user.user_case_groups
     testcase_scene_id = request.args.get('testcase_scene_id')
     testcase_scene = TestCaseScene.query.get(testcase_scene_id)
     FrontLogs('进入编辑测试场景 name: %s 页面' % testcase_scene.name).add_to_front_log()
     return render_template('testcase_scene/testcase_scene_update.html', testcase_scene=testcase_scene,
                            case_groups=case_groups, page=page)
Exemple #28
0
 def get(self):
     page, job_id = request_get_values('page', 'job_id')
     job = Job.query.get(job_id)
     job.is_start = 0
     db.session.commit()
     scheduler_job(job)
     db.session.delete(job)
     db.session.commit()
     FrontLogs('删除测试任务 name: %s 成功' % job.name).add_to_front_log()
     # app.logger.info('message:delete testcases success, id: %s' % id)
     return redirect(url_for('job_blueprint.job_list', page=page))
Exemple #29
0
 def get(self, id=-1):
     case_group = CaseGroup.query.get(id)
     print('CaseGroupSearchCase:case_group: ', case_group)
     testcases = case_group.testcases
     print('CaseGroupSearchCase:testcases: ', testcases)
     request_headers = RequestHeaders.query.all()
     print('CaseGroupSearchCase:request_headers: ', request_headers)
     FrontLogs('进入测试用例分组  id:%s 关联测试用例页面' % id).add_to_front_log()
     return render_template('case_group/case_group_search_case.html',
                            items=testcases,
                            case_group=case_group,
                            request_headers=request_headers)
Exemple #30
0
 def get(self, name):
     download_path = TestCaseStartTimes.query.filter(
         TestCaseStartTimes.name == name).first().filename.replace(
             name, '')
     print('download_path:', download_path)
     dirpath = os.path.join(session.get('app_rootpath'), download_path)
     # 这里是下在目录,从工程的根目录写起,比如你要下载static/js里面的js文件,这里就要写“static/js”
     print('dirpath:', dirpath)
     FrontLogs('下载测试报告 测试报告名称: %s ' % name).add_to_front_log()
     return send_from_directory(
         dirpath, name,
         as_attachment=True)  # as_attachment=True 一定要写,不然会变成打开,而不是下载