def run_test(request): if request.is_ajax(): testcase_lists = json.loads(request.body.decode('utf-8')) if main_ate(testcase_lists): return HttpResponse('ok') else: return HttpResponse('fail')
def run_test(request, mode, id): if request.session.get('login_status'): if request.method == 'GET': if mode == 'run_by_test': result = main_ate(run_by_single(id)) elif mode == 'run_by_module': test_lists = run_by_module(id) result = get_result(test_lists) elif mode == 'run_by_project': test_lists = run_by_project(id) result = get_result(test_lists) return render_to_response('report_template.html', result) else: return HttpResponseRedirect("/api/login/")
def get_result(test_lists): summary = { "success": True, "stat": { 'testsRun': 0, 'successes': 0, 'failures': 0, 'errors': 0, 'skipped': 0, 'expectedFailures': 0, 'unexpectedSuccesses': 0 }, "platform": {}, "time": { 'start_at': '', 'duration': 0.0, }, "records": [], } for index in range(len(test_lists)): result = main_ate(test_lists[index]) if index == 0: summary["time"]["start_at"] = result["time"].pop("start_at") if "html_report_name" in result.keys(): summary["html_report_name"] = result.pop("html_report_name") summary["success"] = summary.pop("success") and result.pop("success") for key, value in result["stat"].items(): summary["stat"][key] = summary["stat"].get(key) + value summary["platform"] = result.pop("platform") summary["time"]["duration"] = summary["time"].pop("duration") + result["time"]["duration"] summary["records"].extend(result.pop("records")) return summary
""" used for debugging """ from httprunner.cli import main_ate main_ate()
def run_test(request, mode, id): if request.method == 'GET': result = main_ate(load_case(mode, id), 'test') report = result.get('reports') return render_to_response('report_view.html', result.get('reports'))
case.pop('is_del') case.pop('suite_id_id') for k, v in case.items(): if v == '' or v is None: case.pop(k) else: try: case[k] = eval(v) except: case[k] = v testcases['testcases'].append(case) testset.update(config) testset.update(testcases) testsets.append(testset) print(testsets) main_ate(testsets) return HttpResponse(request) def add_suite(request): """ 增加一个模块 :param request: :return: 成功返回creat ok """ if request.method == 'POST': suite_data = parse_data_to_object(request.body) suite_name = suite_data['name'] suite_vars = suite_data['variables'] suite_req = suite_data['request'] project_id = suite_data['project_id']