From 14dd6f1fa5905e4aaf5ad3c14c5c841aefeb7f0a Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Thu, 1 Aug 2024 16:23:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E9=85=8D=E7=BD=AE=20(#191)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httpfpt/core/conf.toml | 1 + httpfpt/core/get_conf.py | 1 + httpfpt/utils/request/request_data_parse.py | 10 +++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/httpfpt/core/conf.toml b/httpfpt/core/conf.toml index 24977df..d071158 100644 --- a/httpfpt/core/conf.toml +++ b/httpfpt/core/conf.toml @@ -58,6 +58,7 @@ send = false # 请求发送 [request] +global_env = 'dev.env' timeout = 10 verify = false redirects = true diff --git a/httpfpt/core/get_conf.py b/httpfpt/core/get_conf.py index a1bae83..ab6365b 100644 --- a/httpfpt/core/get_conf.py +++ b/httpfpt/core/get_conf.py @@ -83,6 +83,7 @@ def __init__(self) -> None: self.WECHAT_SEND = glom(self.settings, 'wechat.send') # 请求发送 + self.REQUEST_GLOBAL_ENV = glom(self.settings, 'request.global_env') self.REQUEST_TIMEOUT = glom(self.settings, 'request.timeout') self.REQUEST_VERIFY = glom(self.settings, 'request.verify') self.REQUEST_REDIRECTS = glom(self.settings, 'request.redirects') diff --git a/httpfpt/utils/request/request_data_parse.py b/httpfpt/utils/request/request_data_parse.py index 5378c08..3f93324 100644 --- a/httpfpt/utils/request/request_data_parse.py +++ b/httpfpt/utils/request/request_data_parse.py @@ -15,6 +15,7 @@ from httpfpt.common.env_handler import get_env_dict from httpfpt.common.errors import RequestDataParseError from httpfpt.common.log import log +from httpfpt.core.get_conf import httpfpt_config from httpfpt.core.path_conf import httpfpt_path from httpfpt.db.mysql_db import mysql_client from httpfpt.enums.allure_severity_type import SeverityType @@ -112,10 +113,17 @@ def allure_severity(self) -> str | None: @property def env(self) -> str: + env = httpfpt_config.REQUEST_GLOBAL_ENV + if env: + if not isinstance(env, str): + raise RequestDataParseError(_error_msg('配置文件参数 conf.toml:request:global_env 不是有效的 str 类型')) + if not env.endswith('.env'): + raise RequestDataParseError(_error_msg('配置文件参数 conf.toml:request:global_env 输入不合法')) + return env try: env = self.request_data['config']['request']['env'] except _RequestDataParamGetError: - raise RequestDataParseError(_error_msg('缺少 config:request:env 参数')) + raise RequestDataParseError(_error_msg('缺少 conf.toml:request:global_env 或 config:request:env 参数')) else: if env is None: raise RequestDataParseError(_error_msg('参数 config:request:env 为空'))