Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

feat(数据层): 支持Har格式的用例导入 #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ApiManager/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ <h3 class="am-icon-gears"><em></em> <a href="#">系统设置</a></h3>
uploadAsync: false, //采用同步上传
language: 'zh', //设置语言
uploadUrl: '/api/upload_file/',
allowedFileExtensions: ['yml', 'yaml', 'json'],//接收的文件后缀
allowedFileExtensions: ['yml', 'yaml', 'json','har'],//接收的文件后缀
showUpload: true, //是否显示上传按钮
showRemove: false,
showCaption: true,//是否显示标题
Expand Down