From 531a43f0386f1db3251aa54e19fcf434e877afda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=AD=A6=E5=B3=B0?= Date: Fri, 24 Jun 2022 17:14:00 +0800 Subject: [PATCH] feature:merge import api to one --- services/plan_service.py | 6 ++++-- views/case_view.py | 44 ++++++++++------------------------------ 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/services/plan_service.py b/services/plan_service.py index db1210b..0be67b6 100644 --- a/services/plan_service.py +++ b/services/plan_service.py @@ -2,7 +2,7 @@ from datetime import datetime import sqlalchemy -from app import conf +from app import conf, log from common.enums import Status_EN, Task_Run_Method, Case_Type, Case_Run_Method, User_Role from models.case_model import Case from models.device_model import Device @@ -209,7 +209,9 @@ async def __start_auto_task(auto_tasks): 'test_config': test_config, 'job_type': conf.config['TONE_FUNC_JOB'] }) - await create_tone_job(data) + ret, ok = await create_tone_job(data) + if not ok: + log.logger.debug(ret) task.status = Status_EN.RUNNING.value await task.update() diff --git a/views/case_view.py b/views/case_view.py index 37bb162..c5c2cfa 100644 --- a/views/case_view.py +++ b/views/case_view.py @@ -96,43 +96,21 @@ async def batch_move(request, user_infos): return rsp() -# @bp.post('/import') -async def import_cases(request): - file = request.files.get('excel') - file_type = os.path.splitext(file.name) - - if file_type[1] not in ['.xls', '.xlsx']: - return rsp(code=400, msg=ERROR_OUTLINE_FORMAT) - - await import_excel(file.body) - return rsp() - - -@bp.post('/import/yaml') -@read_auth -async def import_cases_in_yaml_format(request, user_infos): - file = request.files.get('yaml') - file_type = os.path.splitext(file.name) - - if file_type[1] not in ['.yaml']: - return rsp(code=400, msg=ERROR_OUTLINE_FORMAT) - - result, ok = await import_yaml(file.body, file.name) - if not ok: - return rsp(code=500, msg=result) - return rsp() - - -@bp.post('/import/tar') +@bp.post('/import') @read_auth async def import_cases(request, user_infos): - file = request.files.get('tar') + file = request.files.get('file') file_type = os.path.splitext(file.name) - - if file_type[1] not in ['.tar']: + result = '' + ok = True + if file_type[1] in ['.xls', '.xlsx']: + await import_excel(file.body) + elif file_type[1] in ['.yaml', '.yml']: + result, ok = await import_yaml(file.body, file.name) + elif file_type[1] in ['.tar']: + result, ok = await import_tar(file.body, file.name) + else: return rsp(code=400, msg=ERROR_OUTLINE_FORMAT) - - result, ok = await import_tar(file.body, file.name) if not ok: return rsp(code=500, msg=result) return rsp() -- Gitee