Skip to content

Commit

Permalink
更新测试数据存放目录 (#19)
Browse files Browse the repository at this point in the history
* 更新测试数据存放目录

* 修复自动创建测试用例末尾空行

* 修复cli应用退出异常
  • Loading branch information
wu-clan authored Jun 24, 2023
1 parent 2f702dc commit 443d8e1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
9 changes: 9 additions & 0 deletions httpfpt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def testcase_date_verify(verify: str) -> None:
raise typer.Exit(1)
else:
typer.secho('✅ 验证测试数据结构成功', fg='green', bold=True)
raise typer.Exit()


def generate_testcases(generate: bool) -> None:
Expand All @@ -85,6 +86,8 @@ def generate_testcases(generate: bool) -> None:
except Exception as e:
typer.secho(f'❌ 自动生成测试用例失败: {e}', fg='red', bold=True)
raise typer.Exit(1)
else:
raise typer.Exit()


def import_openapi_test_data(openapi: tuple) -> None:
Expand All @@ -98,6 +101,8 @@ def import_openapi_test_data(openapi: tuple) -> None:
except Exception as e:
typer.secho('❌ 导入 openapi 数据失败', fg='red', bold=True)
raise e
else:
raise typer.Exit()
else:
raise typer.Abort()

Expand All @@ -120,6 +125,8 @@ def import_apifox_test_data(apifox: tuple) -> None:
except Exception as e:
typer.secho('❌ 导入 apifox 数据失败:', fg='red', bold=True)
raise e
else:
raise typer.Exit()
else:
raise typer.Abort()

Expand Down Expand Up @@ -148,6 +155,8 @@ def import_git_case_data(src: str) -> None:
except Exception as e:
typer.secho(f'❌ 导入 git 仓库测试数据失败: {e}', fg='red', bold=True)
raise e
else:
raise typer.Exit()


@app.callback(name='version')
Expand Down
2 changes: 1 addition & 1 deletion httpfpt/core/path_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
TEST_DATA_PATH = os.path.join(BASE_DIR, 'data')

# Yaml测试数据路径
YAML_DATA_PATH = os.path.join(TEST_DATA_PATH, 'test_data', 'yaml_data')
YAML_DATA_PATH = os.path.join(TEST_DATA_PATH, 'test_data')

# 测试报告路径
TEST_REPORT_PATH = os.path.join(BASE_DIR, 'report')
Expand Down
3 changes: 1 addition & 2 deletions httpfpt/utils/case_auto_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ class {testcase_class_name}:
def {testcase_func_name}(self, data):
"""{create_file_root_name}"""
send_request.send_request(data)
'''
'''
# 创建测试用例文件
tag = str(Path(yaml_filename).parent)[1:]
if tag != '':
Expand Down
8 changes: 4 additions & 4 deletions httpfpt/utils/data_manage/git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ def import_git_to_local(src: str) -> None:
"""

if 'https' not in src:
raise ValueError('git 仓库克隆地址错误, 请使用 https 地址')
raise ValueError('git 仓库克隆地址错误, 请使用 https 地址')

try:
online_dir_path = os.path.join(os.path.abspath('./data/test_data'), 'online_yaml_data')
online_dir_path = os.path.join(os.path.abspath('./data/test_data'), 'online_test_data')
typer.echo(online_dir_path)
if os.path.exists(online_dir_path):
shutil.rmtree(online_dir_path)
os.makedirs(online_dir_path)
result = os.system(f'cd {online_dir_path} && git clone {src}')
except Exception as e:
raise RuntimeError(f'git 苍鹭测试数据拉取失败{e}')
raise RuntimeError(f'git 仓库测试数据拉取失败{e}')
else:
if result == 0:
typer.secho('✅ git 仓库数据文件拉取成功')
else:
raise RuntimeError('git 仓库测试数据拉取失败')
raise RuntimeError('git 仓库测试数据拉取失败')

all_yaml_file = search_all_case_yaml_files(online_dir_path)
all_case_data = []
Expand Down

0 comments on commit 443d8e1

Please sign in to comment.