From 9dbf33bd4ea6f54807cd47e6d0fdf4ac21426f05 Mon Sep 17 00:00:00 2001 From: yileye <695084435@qq.com> Date: Thu, 20 Sep 2018 18:24:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=95=B0=E6=8D=AE=E5=B1=82):=20=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81Har=E6=A0=BC=E5=BC=8F=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 引入har2case,支持charles接口转化为平台中的用例 --- ApiManager/utils/common.py | 12 ++++++++++++ templates/base.html | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ApiManager/utils/common.py b/ApiManager/utils/common.py index 2d50f75..71336dc 100644 --- a/ApiManager/utils/common.py +++ b/ApiManager/utils/common.py @@ -10,6 +10,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.db.models import Sum from djcelery.models import PeriodicTask +from har2case.core import HarParser from ApiManager.models import ModuleInfo, TestCaseInfo, TestReports, TestSuite from ApiManager.utils.operation import add_project_data, add_module_data, add_case_data, add_config_data, \ @@ -538,6 +539,17 @@ def upload_file_logic(files, project, module, account): with io.open(file, 'r', encoding='utf-8') as stream: content = yaml.load(stream) + elif file_suffix in ['.har']: + hp = HarParser(file) + jfile = os.path.splitext(file)[0] + '.json' + hp.gen_json(jfile) + with io.open(jfile, encoding='utf-8') as json_file: + try: + content = json.load(json_file) + except JSONDecodeError: + err_msg = u"JSONDecodeError: JSON file format error: {}".format(file) + logging.error(err_msg) + for test_case in content: test_dict = { 'project': project, diff --git a/templates/base.html b/templates/base.html index 677c1f9..7404ff5 100644 --- a/templates/base.html +++ b/templates/base.html @@ -215,7 +215,7 @@