Ejemplo n.º 1
0
def case_view():
    db = MongoClient()
    caseList = db.get_case_list()
    del db
    return render_template('case_list.html',
                           posts=caseList,
                           user=session.get('user'))
Ejemplo n.º 2
0
def edit_case():
    db = None
    rt = {'code': 500, 'error': '', 'status': 0}
    case_info = {}
    try:
        data = request.form
        if data:
            _id = data.get('_id')
            expect = data.get('expected')
            case_name = str(data.get('case_name'))
            params = data.get('params')
            method = data.get('method')
            _assert = data.get('assert')
            url = data.get('url')
            headers = data.get('headers')
            content = data.get('content', '')
            precondition = data.get("precondition")
            sql_prepare = data.get('sql_prepare')
            sql_verify = data.get('sql_verify')
            sql_clean = data.get('sql_clean')
            case_info.update(
                dict(expected=expect,
                     enable=True,
                     name=case_name,
                     params=params,
                     _assert=_assert,
                     url=url,
                     content=content,
                     method=method,
                     headers=headers,
                     sql_clean=sql_clean,
                     sql_verify=sql_verify,
                     sql_prepare=sql_prepare,
                     pre=precondition))
            case_info = Operator.transfer_str(**case_info)
            if expect and case_name and method and url and headers:
                if method.lower() == 'post':
                    if not params:
                        raise Exception(
                            'Please provide params for post method.')
                db = MongoClient()
                result = db.edit_case(_id, case_info)
                if result.raw_result['ok']:
                    rt.update(
                        dict(code=200,
                             status=1,
                             msg='Add a case Successfully.'))
            else:
                raise Exception('Please check your params for case_info.')
    except Exception as err:
        logging.error('create_case error: {}'.format(str(err)))
        rt.update(dict(error=str(err)))
    finally:
        if db:
            del db
    return jsonify(rt)
Ejemplo n.º 3
0
def get_homework():
    if session.get('user'):
        obj = MongoClient()
        db = obj.get_db()
        homework = list(db.homework.find())
        return render_template('homework.html',
                               user=session.get('user'),
                               homework=homework)
    else:
        return render_template('login.html')
Ejemplo n.º 4
0
def delete_case():
    rt = {'status': False, 'msg': None}
    try:
        data = request.get_json()
        case_name = data.get('case_name')
        db = MongoClient()
        db.delete_case(case_name)
        del db
        rt.update(dict(status=True))
    except Exception as err:
        print("{} error: {}".format(Operator.get_current_func(), str(err)))
    return jsonify(rt)
Ejemplo n.º 5
0
def run_selected_case():
    # return jsonify(dict(name='selenium'))

    data = request.get_json()
    start = handle.now_str()
    # 先找到mongo里的case信息
    db = MongoClient()
    case_list = db.get_case_by_name(data.get('case_name'))
    obj = apiFunc()
    rt = obj.run_tests(case_list, app.config['THREAD_NUM'])
    report = obj.writeReport(rt)
    html = render_template('testResult.html',
                           failNum=rt['failed_num'],
                           ignored=rt['ignored'],
                           successNum=rt['success_num'],
                           total=rt['total'],
                           start=start,
                           end=handle.now_str(),
                           cost="{:.2}秒".format(
                               handle.delta(start, handle.now_str())),
                           fileName=report)
    return jsonify(dict(html=html))
Ejemplo n.º 6
0
def edit_page(case_name):
    db = MongoClient()
    case = db.get_case_info(case_name)
    case = Operator.transfer_case_info(case)
    return render_template('edit_case.html', case=case)