修复动态加载函数的bug
This commit is contained in:
parent
49bee29250
commit
e20a6a26cf
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GitToolBoxProjectSettings">
|
||||||
|
<option name="commitMessageIssueKeyValidationOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
<option name="commitMessageValidationEnabledOverride">
|
||||||
|
<BoolValueOverride>
|
||||||
|
<option name="enabled" value="true" />
|
||||||
|
</BoolValueOverride>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -4,12 +4,15 @@
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="eded71e8-6551-463d-9bd4-cdbb3ffc536c" name="更改" comment="删除多余的文件">
|
<list default="true" id="eded71e8-6551-463d-9bd4-cdbb3ffc536c" name="更改" comment="测试浏览记录到csv">
|
||||||
|
<change afterPath="$PROJECT_DIR$/encryption_rules/__init__.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/debug/cap.py" beforeDir="false" />
|
<change beforePath="$PROJECT_DIR$/common/crypto/encrypt_data.py" beforeDir="false" afterPath="$PROJECT_DIR$/common/crypto/encrypt_data.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/debug/requestRecord.py" beforeDir="false" afterPath="$PROJECT_DIR$/debug/requestRecord.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/common/utils/action.py" beforeDir="false" afterPath="$PROJECT_DIR$/common/utils/action.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/debug/test15.csv" beforeDir="false" />
|
<change beforePath="$PROJECT_DIR$/common/validation/load_modules_from_folder.py" beforeDir="false" afterPath="$PROJECT_DIR$/common/validation/load_modules_from_folder.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/filtered_requests.csv" beforeDir="false" />
|
<change beforePath="$PROJECT_DIR$/extensions/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/extensions/__init__.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/extensions/sign.py" beforeDir="false" afterPath="$PROJECT_DIR$/encryption_rules/rules.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/test_script/test_executor.py" beforeDir="false" afterPath="$PROJECT_DIR$/test_script/test_executor.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -66,34 +69,13 @@
|
||||||
}</component>
|
}</component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="MoveFile.RECENT_KEYS">
|
<key name="MoveFile.RECENT_KEYS">
|
||||||
|
<recent name="D:\app\apitest\encryption_rules" />
|
||||||
<recent name="D:\app\apitest\common\validation" />
|
<recent name="D:\app\apitest\common\validation" />
|
||||||
<recent name="D:\app\apitest\common\log_utils" />
|
<recent name="D:\app\apitest\common\log_utils" />
|
||||||
<recent name="D:\app\apitest\common\parsing" />
|
<recent name="D:\app\apitest\common\parsing" />
|
||||||
</key>
|
</key>
|
||||||
</component>
|
</component>
|
||||||
<component name="RunManager" selected="Python.http_client">
|
<component name="RunManager" selected="Python.load_modules_from_folder">
|
||||||
<configuration name="encryption_str" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
|
||||||
<module name="api_project" />
|
|
||||||
<option name="INTERPRETER_OPTIONS" value="" />
|
|
||||||
<option name="PARENT_ENVS" value="true" />
|
|
||||||
<envs>
|
|
||||||
<env name="PYTHONUNBUFFERED" value="1" />
|
|
||||||
</envs>
|
|
||||||
<option name="SDK_HOME" value="" />
|
|
||||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/common/crypto" />
|
|
||||||
<option name="IS_MODULE_SDK" value="true" />
|
|
||||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
|
||||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
|
||||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
|
||||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/common/crypto/encryption_str.py" />
|
|
||||||
<option name="PARAMETERS" value="" />
|
|
||||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
|
||||||
<option name="EMULATE_TERMINAL" value="false" />
|
|
||||||
<option name="MODULE_MODE" value="false" />
|
|
||||||
<option name="REDIRECT_INPUT" value="false" />
|
|
||||||
<option name="INPUT_FILE" value="" />
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
<configuration name="http_client" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
<configuration name="http_client" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||||
<module name="api_project" />
|
<module name="api_project" />
|
||||||
<option name="INTERPRETER_OPTIONS" value="" />
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
@ -116,6 +98,50 @@
|
||||||
<option name="INPUT_FILE" value="" />
|
<option name="INPUT_FILE" value="" />
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration name="load_modules_from_folder" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="api_project" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<envs>
|
||||||
|
<env name="PYTHONUNBUFFERED" value="1" />
|
||||||
|
</envs>
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/common/validation" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||||
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/common/validation/load_modules_from_folder.py" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||||
|
<option name="EMULATE_TERMINAL" value="false" />
|
||||||
|
<option name="MODULE_MODE" value="false" />
|
||||||
|
<option name="REDIRECT_INPUT" value="false" />
|
||||||
|
<option name="INPUT_FILE" value="" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<configuration name="loaders" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="api_project" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="PARENT_ENVS" value="true" />
|
||||||
|
<envs>
|
||||||
|
<env name="PYTHONUNBUFFERED" value="1" />
|
||||||
|
</envs>
|
||||||
|
<option name="SDK_HOME" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/common/validation" />
|
||||||
|
<option name="IS_MODULE_SDK" value="true" />
|
||||||
|
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||||
|
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||||
|
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||||
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/common/validation/loaders.py" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||||
|
<option name="EMULATE_TERMINAL" value="false" />
|
||||||
|
<option name="MODULE_MODE" value="false" />
|
||||||
|
<option name="REDIRECT_INPUT" value="false" />
|
||||||
|
<option name="INPUT_FILE" value="" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
<configuration name="mysql_client" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
<configuration name="mysql_client" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||||
<module name="api_project" />
|
<module name="api_project" />
|
||||||
<option name="INTERPRETER_OPTIONS" value="" />
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
@ -138,28 +164,6 @@
|
||||||
<option name="INPUT_FILE" value="" />
|
<option name="INPUT_FILE" value="" />
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="requestRecord (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
|
||||||
<module name="api_project" />
|
|
||||||
<option name="INTERPRETER_OPTIONS" value="" />
|
|
||||||
<option name="PARENT_ENVS" value="true" />
|
|
||||||
<envs>
|
|
||||||
<env name="PYTHONUNBUFFERED" value="1" />
|
|
||||||
</envs>
|
|
||||||
<option name="SDK_HOME" value="" />
|
|
||||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/debug" />
|
|
||||||
<option name="IS_MODULE_SDK" value="true" />
|
|
||||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
|
||||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
|
||||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
|
||||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/debug/requestRecord.py" />
|
|
||||||
<option name="PARAMETERS" value="" />
|
|
||||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
|
||||||
<option name="EMULATE_TERMINAL" value="false" />
|
|
||||||
<option name="MODULE_MODE" value="false" />
|
|
||||||
<option name="REDIRECT_INPUT" value="false" />
|
|
||||||
<option name="INPUT_FILE" value="" />
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
<configuration name="Unittest (test_executor.py 内)" type="tests" factoryName="Unittests" temporary="true" nameIsGenerated="true">
|
<configuration name="Unittest (test_executor.py 内)" type="tests" factoryName="Unittests" temporary="true" nameIsGenerated="true">
|
||||||
<module name="api_project" />
|
<module name="api_project" />
|
||||||
<option name="INTERPRETER_OPTIONS" value="" />
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
@ -177,11 +181,11 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Python.load_modules_from_folder" />
|
||||||
|
<item itemvalue="Python.loaders" />
|
||||||
<item itemvalue="Python.http_client" />
|
<item itemvalue="Python.http_client" />
|
||||||
<item itemvalue="Python 测试.Unittest (test_executor.py 内)" />
|
<item itemvalue="Python 测试.Unittest (test_executor.py 内)" />
|
||||||
<item itemvalue="Python.mysql_client" />
|
<item itemvalue="Python.mysql_client" />
|
||||||
<item itemvalue="Python.encryption_str" />
|
|
||||||
<item itemvalue="Python.requestRecord (1)" />
|
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
|
@ -211,7 +215,8 @@
|
||||||
<workItem from="1690536254640" duration="11000" />
|
<workItem from="1690536254640" duration="11000" />
|
||||||
<workItem from="1690774476519" duration="12117000" />
|
<workItem from="1690774476519" duration="12117000" />
|
||||||
<workItem from="1690855086910" duration="749000" />
|
<workItem from="1690855086910" duration="749000" />
|
||||||
<workItem from="1690855882311" duration="1790000" />
|
<workItem from="1690855882311" duration="1981000" />
|
||||||
|
<workItem from="1690873614157" duration="4763000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="优化代码">
|
<task id="LOCAL-00001" summary="优化代码">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
@ -285,7 +290,15 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1690854560996</updated>
|
<updated>1690854560996</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="10" />
|
<task id="LOCAL-00010" summary="测试浏览记录到csv">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1690858708660</created>
|
||||||
|
<option name="number" value="00010" />
|
||||||
|
<option name="presentableId" value="LOCAL-00010" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1690858708660</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="11" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
@ -298,7 +311,8 @@
|
||||||
<MESSAGE value="增加统一自定义异常类" />
|
<MESSAGE value="增加统一自定义异常类" />
|
||||||
<MESSAGE value="gitignore" />
|
<MESSAGE value="gitignore" />
|
||||||
<MESSAGE value="删除多余的文件" />
|
<MESSAGE value="删除多余的文件" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="删除多余的文件" />
|
<MESSAGE value="测试浏览记录到csv" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="测试浏览记录到csv" />
|
||||||
</component>
|
</component>
|
||||||
<component name="com.github.evgenys91.machinet.common.dslhistory.DslHistoryState">
|
<component name="com.github.evgenys91.machinet.common.dslhistory.DslHistoryState">
|
||||||
<option name="historyDtoById">
|
<option name="historyDtoById">
|
||||||
|
@ -318,6 +332,8 @@
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||||
|
<SUITE FILE_PATH="coverage/apitest$loaders.coverage" NAME="loaders 覆盖结果" MODIFIED="1690874206675" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/common/validation" />
|
||||||
|
<SUITE FILE_PATH="coverage/apitest$load_modules_from_folder.coverage" NAME="load_modules_from_folder 覆盖结果" MODIFIED="1690882059703" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/common/validation" />
|
||||||
<SUITE FILE_PATH="coverage/apitest$requestRecord__1_.coverage" NAME="requestRecord (1) 覆盖结果" MODIFIED="1690531988570" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/debug" />
|
<SUITE FILE_PATH="coverage/apitest$requestRecord__1_.coverage" NAME="requestRecord (1) 覆盖结果" MODIFIED="1690531988570" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/debug" />
|
||||||
<SUITE FILE_PATH="coverage/apitest$Unittest__test_executor_py__.coverage" NAME="Unittest (test_executor.py 内) 覆盖结果" MODIFIED="1690850721335" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test_script" />
|
<SUITE FILE_PATH="coverage/apitest$Unittest__test_executor_py__.coverage" NAME="Unittest (test_executor.py 内) 覆盖结果" MODIFIED="1690850721335" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/test_script" />
|
||||||
<SUITE FILE_PATH="coverage/apitest$action.coverage" NAME="action 覆盖结果" MODIFIED="1689907783681" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/common" />
|
<SUITE FILE_PATH="coverage/apitest$action.coverage" NAME="action 覆盖结果" MODIFIED="1689907783681" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/common" />
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
from common.crypto import logger
|
from common.crypto import logger
|
||||||
from common.crypto.encryption_rsa import Rsa
|
from common.crypto.encryption_rsa import Rsa
|
||||||
# from common.crypto.encryption_aes import DoAES
|
# from common.crypto.encryption_aes import DoAES
|
||||||
from extensions import sign
|
from encryption_rules import rules
|
||||||
|
|
||||||
|
|
||||||
@logger.log_decorator()
|
@logger.log_decorator()
|
||||||
|
@ -21,8 +21,8 @@ class EncryptData:
|
||||||
|
|
||||||
def encrypts(self, headers_crypto, headers, request_data_crypto, request_data):
|
def encrypts(self, headers_crypto, headers, request_data_crypto, request_data):
|
||||||
encryption_methods = {
|
encryption_methods = {
|
||||||
"MD5": sign.md5_sign,
|
"MD5": rules.md5_sign,
|
||||||
"sha1": sign.sha1_sign,
|
"sha1": rules.sha1_sign,
|
||||||
"rsa": lambda data: Rsa(data).rsa_encrypt()
|
"rsa": lambda data: Rsa(data).rsa_encrypt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
import ast
|
import ast
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from common import bif_functions
|
||||||
from common.crypto.encrypt_data import EncryptData
|
from common.crypto.encrypt_data import EncryptData
|
||||||
from common.database.mysql_client import MysqlClient
|
from common.database.mysql_client import MysqlClient
|
||||||
from common.log_utils.mylogger import MyLogger
|
from common.log_utils.mylogger import MyLogger
|
||||||
|
@ -22,7 +23,7 @@ from common.validation.validator import Validator
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class Action(Extractor, LoadScript, Validator, MysqlClient):
|
class Action(Extractor, LoadScript, Validator, MysqlClient):
|
||||||
def __init__(self, initialize_data=None, bif_functions=None, db_config=None):
|
def __init__(self, initialize_data=None, db_config=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
MysqlClient.__init__(self, db_config)
|
MysqlClient.__init__(self, db_config)
|
||||||
self.encrypt = EncryptData()
|
self.encrypt = EncryptData()
|
||||||
|
@ -30,7 +31,7 @@ class Action(Extractor, LoadScript, Validator, MysqlClient):
|
||||||
self.set_environments(initialize_data)
|
self.set_environments(initialize_data)
|
||||||
self.set_bif_fun(bif_functions)
|
self.set_bif_fun(bif_functions)
|
||||||
self.logger = MyLogger()
|
self.logger = MyLogger()
|
||||||
|
|
||||||
def execute_dynamic_code(self, item, code):
|
def execute_dynamic_code(self, item, code):
|
||||||
self.variables = item
|
self.variables = item
|
||||||
if code is not None:
|
if code is not None:
|
||||||
|
@ -42,20 +43,20 @@ class Action(Extractor, LoadScript, Validator, MysqlClient):
|
||||||
ExecuteDynamiCodeError(code, e)
|
ExecuteDynamiCodeError(code, e)
|
||||||
except ExecuteDynamiCodeError as e:
|
except ExecuteDynamiCodeError as e:
|
||||||
ExecuteDynamiCodeError(code, e)
|
ExecuteDynamiCodeError(code, e)
|
||||||
|
|
||||||
return self.variables
|
return self.variables
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def variables(self, key=None):
|
def variables(self, key=None):
|
||||||
return self.__variables if not key else self.__variables.get(key)
|
return self.__variables if not key else self.__variables.get(key)
|
||||||
|
|
||||||
@variables.setter
|
@variables.setter
|
||||||
def variables(self, item):
|
def variables(self, item):
|
||||||
self.__variables = item
|
self.__variables = item
|
||||||
|
|
||||||
# def update_variables(self, key, value):
|
# def update_variables(self, key, value):
|
||||||
# self.__variables[f"{{{{{key}}}}}"] = value
|
# self.__variables[f"{{{{{key}}}}}"] = value
|
||||||
|
|
||||||
def analysis_request(self, request_data, headers_crypto, headers, request_crypto, extract_request_data):
|
def analysis_request(self, request_data, headers_crypto, headers, request_crypto, extract_request_data):
|
||||||
# 请求头及body加密或者加签
|
# 请求头及body加密或者加签
|
||||||
headers, request_data = self.encrypt.encrypts(headers_crypto, headers, request_crypto, request_data)
|
headers, request_data = self.encrypt.encrypts(headers_crypto, headers, request_crypto, request_data)
|
||||||
|
@ -63,12 +64,12 @@ class Action(Extractor, LoadScript, Validator, MysqlClient):
|
||||||
if extract_request_data is not None and request_data is not None:
|
if extract_request_data is not None and request_data is not None:
|
||||||
self.substitute_data(request_data, jp_dict=extract_request_data)
|
self.substitute_data(request_data, jp_dict=extract_request_data)
|
||||||
return headers, request_data
|
return headers, request_data
|
||||||
|
|
||||||
def send_request(self, host, url, method, teardown_script, **kwargs):
|
def send_request(self, host, url, method, teardown_script, **kwargs):
|
||||||
self.http_client(host, url, method, **kwargs)
|
self.http_client(host, url, method, **kwargs)
|
||||||
self.update_environments("responseTime", self.response.elapsed.total_seconds() * 1000) # 存响应时间
|
self.update_environments("responseTime", self.response.elapsed.total_seconds() * 1000) # 存响应时间
|
||||||
self.execute_dynamic_code(self.response, teardown_script)
|
self.execute_dynamic_code(self.response, teardown_script)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def base_info(item):
|
def base_info(item):
|
||||||
"""
|
"""
|
||||||
|
@ -85,13 +86,13 @@ class Action(Extractor, LoadScript, Validator, MysqlClient):
|
||||||
method = item.pop("Method")
|
method = item.pop("Method")
|
||||||
expected = item.pop("Expected")
|
expected = item.pop("Expected")
|
||||||
return sheet, item_id, condition, sleep_time, name, desc, headers_crypto, request_data_crypto, method, expected
|
return sheet, item_id, condition, sleep_time, name, desc, headers_crypto, request_data_crypto, method, expected
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sql_info(item):
|
def sql_info(item):
|
||||||
sql = item.pop("SQL")
|
sql = item.pop("SQL")
|
||||||
sql_params_dict = item.pop("Sql Params Dict")
|
sql_params_dict = item.pop("Sql Params Dict")
|
||||||
return sql, sql_params_dict
|
return sql, sql_params_dict
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def extractor_info(item):
|
def extractor_info(item):
|
||||||
"""
|
"""
|
||||||
|
@ -108,7 +109,7 @@ class Action(Extractor, LoadScript, Validator, MysqlClient):
|
||||||
jp_dict = item.pop("Jsonpath")
|
jp_dict = item.pop("Jsonpath")
|
||||||
extract_request_data = item.pop("Extract Request Data")
|
extract_request_data = item.pop("Extract Request Data")
|
||||||
return regex, keys, deps, jp_dict, extract_request_data
|
return regex, keys, deps, jp_dict, extract_request_data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def request_info(item):
|
def request_info(item):
|
||||||
"""
|
"""
|
||||||
|
@ -119,28 +120,28 @@ class Action(Extractor, LoadScript, Validator, MysqlClient):
|
||||||
request_data = item.pop("Request Data")
|
request_data = item.pop("Request Data")
|
||||||
headers = item.pop("Headers")
|
headers = item.pop("Headers")
|
||||||
request_data_type = item.pop("Request Data Type") if item.get("Request Data Type") else 'params'
|
request_data_type = item.pop("Request Data Type") if item.get("Request Data Type") else 'params'
|
||||||
|
|
||||||
return url, query_str, request_data, headers, request_data_type
|
return url, query_str, request_data, headers, request_data_type
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def script(item):
|
def script(item):
|
||||||
setup_script = item.pop("Setup Script")
|
setup_script = item.pop("Setup Script")
|
||||||
teardown_script = item.pop("Teardown Script")
|
teardown_script = item.pop("Teardown Script")
|
||||||
return setup_script, teardown_script
|
return setup_script, teardown_script
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_run(condition):
|
def is_run(condition):
|
||||||
is_run = condition
|
is_run = condition
|
||||||
if not is_run or is_run.upper() != "YES":
|
if not is_run or is_run.upper() != "YES":
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def pause_execution(self, sleep_time):
|
def pause_execution(self, sleep_time):
|
||||||
if sleep_time:
|
if sleep_time:
|
||||||
try:
|
try:
|
||||||
time.sleep(sleep_time)
|
time.sleep(sleep_time)
|
||||||
except MyBaseException as e:
|
except MyBaseException as e:
|
||||||
raise MyBaseException(f"暂停时间必须是数字!")
|
raise MyBaseException(f"暂停时间必须是数字!")
|
||||||
|
|
||||||
def exc_sql(self, item):
|
def exc_sql(self, item):
|
||||||
sql, sql_params_dict = self.sql_info(item)
|
sql, sql_params_dict = self.sql_info(item)
|
||||||
sql = self.replace_dependent_parameter(sql)
|
sql = self.replace_dependent_parameter(sql)
|
||||||
|
|
|
@ -9,53 +9,54 @@
|
||||||
"""
|
"""
|
||||||
import importlib.util
|
import importlib.util
|
||||||
import os
|
import os
|
||||||
|
import types
|
||||||
|
|
||||||
from common.data_extraction.dependent_parameter import DependentParameter
|
from common.data_extraction.dependent_parameter import DependentParameter
|
||||||
from common.validation import logger
|
from common.validation import logger
|
||||||
|
|
||||||
|
|
||||||
# from common.environments import Environments
|
|
||||||
# from common.data_extraction.data_extractor import DataExtractor
|
|
||||||
|
|
||||||
|
|
||||||
class LoadModulesFromFolder(DependentParameter):
|
class LoadModulesFromFolder(DependentParameter):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
@logger.log_decorator()
|
@logger.log_decorator()
|
||||||
def load_modules_from_folder(self, folder_path):
|
def load_modules_from_folder(self, folder_or_mnodule):
|
||||||
"""
|
"""
|
||||||
动态加载指定文件夹下的模块,并读取其中的函数
|
动态加载文件或模块
|
||||||
通过访问字典的 key 可以获取到对应的函数值并调用。
|
"""
|
||||||
|
|
||||||
Args:
|
if isinstance(folder_or_mnodule, str):
|
||||||
folder_path (str): 要加载模块的文件夹路径
|
folder_path = folder_or_mnodule
|
||||||
|
if not os.path.exists(folder_path): # 检查文件夹路径是否存在
|
||||||
Returns:
|
raise ValueError("Folder path does not exist.")
|
||||||
dict: 存储函数的字典,键为函数名,值为函数对象
|
|
||||||
"""
|
for file_name in os.listdir(folder_path): # 遍历指定文件夹下的所有文件
|
||||||
|
module_name, ext = os.path.splitext(file_name)
|
||||||
if not os.path.exists(folder_path): # 检查文件夹路径是否存在
|
if ext == '.py' and module_name != '__init__':
|
||||||
raise ValueError("Folder path does not exist.")
|
module_path = os.path.join(folder_path, file_name) # 获取模块文件的完整路径
|
||||||
|
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
||||||
for file_name in os.listdir(folder_path): # 遍历指定文件夹下的所有文件
|
module = importlib.util.module_from_spec(spec)
|
||||||
module_name, ext = os.path.splitext(file_name)
|
try:
|
||||||
if ext == '.py' and module_name != '__init__': # 如果是 Python 模块文件
|
spec.loader.exec_module(module) # 加载模块文件并执行其中的代码,将函数定义添加到 module 对象中
|
||||||
module_path = os.path.join(folder_path, file_name) # 获取模块文件的完整路径
|
except:
|
||||||
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
continue
|
||||||
module = importlib.util.module_from_spec(spec)
|
for name, obj in vars(module).items():
|
||||||
try:
|
if callable(obj):
|
||||||
spec.loader.exec_module(module) # 加载模块文件并执行其中的代码,将函数定义添加到 module 对象中
|
self.update_environments(name, obj)
|
||||||
except Exception as e:
|
elif isinstance(folder_or_mnodule, types.ModuleType):
|
||||||
continue
|
module = folder_or_mnodule
|
||||||
|
module = importlib.reload(module)
|
||||||
# 遍历 module 对象中的所有属性,找出函数并添加到 functions 字典中
|
for n, o in vars(module).items():
|
||||||
for name, obj in vars(module).items():
|
if callable(o):
|
||||||
if callable(obj):
|
self.update_environments(n, o)
|
||||||
self.update_environments(name, obj)
|
else:
|
||||||
|
raise TypeError("folder_or_module should be either a folder path (str) or a module (types.ModuleType).")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
lmff = LoadModulesFromFolder()
|
lmff = LoadModulesFromFolder()
|
||||||
lmff.load_modules_from_folder(r'D:\apk_api\api-test-project\extensions')
|
# lmff.load_modules_from_folder(r'..\..\extensions')
|
||||||
print(lmff.get_environments())
|
import extensions as es
|
||||||
|
|
||||||
|
lmff.load_modules_from_folder(es)
|
||||||
|
print(lmff.get_environments())
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
"""
|
||||||
|
@author: kira
|
||||||
|
@contact: 262667641@qq.com
|
||||||
|
@file: __init__.py.py
|
||||||
|
@time: 2023/8/1 17:07
|
||||||
|
@desc:
|
||||||
|
"""
|
|
@ -3,9 +3,9 @@
|
||||||
"""
|
"""
|
||||||
@author: kira
|
@author: kira
|
||||||
@contact: 262667641@qq.com
|
@contact: 262667641@qq.com
|
||||||
@file: do_sign.py
|
@file: rules.py
|
||||||
@time: 2023/3/14 16:21
|
@time: 2023/3/14 16:21
|
||||||
@desc:
|
@desc:自定义加密规则
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
|
@ -12,4 +12,3 @@ from common.log_utils.mylogger import MyLogger
|
||||||
logger = MyLogger()
|
logger = MyLogger()
|
||||||
|
|
||||||
from .dynamic_scaling_methods import *
|
from .dynamic_scaling_methods import *
|
||||||
from .sign import *
|
|
||||||
|
|
|
@ -11,11 +11,10 @@ import unittest
|
||||||
|
|
||||||
from ddt import ddt, data
|
from ddt import ddt, data
|
||||||
|
|
||||||
from common import bif_functions
|
import extensions
|
||||||
from common.file_handling.do_excel import DoExcel
|
from common.file_handling.do_excel import DoExcel
|
||||||
from common.utils.action import Action
|
from common.utils.action import Action
|
||||||
from config import Config
|
from config import Config
|
||||||
from extensions import dynamic_scaling_methods
|
|
||||||
|
|
||||||
test_file = Config.test_case # 获取 excel 文件路径
|
test_file = Config.test_case # 获取 excel 文件路径
|
||||||
excel = DoExcel(test_file)
|
excel = DoExcel(test_file)
|
||||||
|
@ -26,15 +25,15 @@ test_case, databases, initialize_data, host = excel.get_excel_init_and_cases()
|
||||||
@ddt
|
@ddt
|
||||||
class TestProjectApi(unittest.TestCase):
|
class TestProjectApi(unittest.TestCase):
|
||||||
maxDiff = None
|
maxDiff = None
|
||||||
action = Action(initialize_data, bif_functions, databases)
|
action = Action(initialize_data, databases)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls) -> None:
|
def setUpClass(cls) -> None:
|
||||||
pass
|
cls.action.load_modules_from_folder(extensions)
|
||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.action.set_bif_fun(dynamic_scaling_methods)
|
pass
|
||||||
|
|
||||||
@data(*test_case)
|
@data(*test_case)
|
||||||
def test_api(self, item):
|
def test_api(self, item):
|
||||||
sheet, iid, condition, st, name, desc, h_crypto, r_crypto, method, expected = self.action.base_info(item)
|
sheet, iid, condition, st, name, desc, h_crypto, r_crypto, method, expected = self.action.base_info(item)
|
||||||
|
@ -43,30 +42,30 @@ class TestProjectApi(unittest.TestCase):
|
||||||
regex, keys, deps, jp_dict, ex_request_data = self.action.extractor_info(item)
|
regex, keys, deps, jp_dict, ex_request_data = self.action.extractor_info(item)
|
||||||
setup_script, teardown_script = self.action.script(item)
|
setup_script, teardown_script = self.action.script(item)
|
||||||
self.action.pause_execution(st)
|
self.action.pause_execution(st)
|
||||||
|
|
||||||
# 首执行 sql
|
# 首执行 sql
|
||||||
self.action.exc_sql(item)
|
self.action.exc_sql(item)
|
||||||
if method.upper() == 'SQL':
|
if method.upper() == 'SQL':
|
||||||
self.skipTest("这条测试用例被 SQL 吃了,所以放弃执行了!!")
|
self.skipTest("这条测试用例被 SQL 吃了,所以放弃执行了!!")
|
||||||
|
|
||||||
# 执行动态代码
|
# 执行动态代码
|
||||||
item = self.action.execute_dynamic_code(item, setup_script)
|
item = self.action.execute_dynamic_code(item, setup_script)
|
||||||
|
|
||||||
# prepost_script = f"prepost_script_{sheet}_{iid}.py"
|
# prepost_script = f"prepost_script_{sheet}_{iid}.py"
|
||||||
# item = self.action.load_and_execute_script(Config.SCRIPTS_DIR, prepost_script, "setup", item)
|
# item = self.action.load_and_execute_script(Config.SCRIPTS_DIR, prepost_script, "setup", item)
|
||||||
|
|
||||||
# 修正参数
|
# 修正参数
|
||||||
item = self.action.replace_dependent_parameter(item)
|
item = self.action.replace_dependent_parameter(item)
|
||||||
url, query_str, request_data, headers, request_data_type = self.action.request_info(item)
|
url, query_str, request_data, headers, request_data_type = self.action.request_info(item)
|
||||||
|
|
||||||
# 分析请求参数信息
|
# 分析请求参数信息
|
||||||
headers, request_data = self.action.analysis_request(request_data, h_crypto, headers, r_crypto, ex_request_data)
|
headers, request_data = self.action.analysis_request(request_data, h_crypto, headers, r_crypto, ex_request_data)
|
||||||
result = "PASS"
|
result = "PASS"
|
||||||
|
|
||||||
# 执行请求操作
|
# 执行请求操作
|
||||||
kwargs = {request_data_type: request_data, 'headers': headers, "params": query_str}
|
kwargs = {request_data_type: request_data, 'headers': headers, "params": query_str}
|
||||||
self.action.send_request(host, url, method, teardown_script, **kwargs)
|
self.action.send_request(host, url, method, teardown_script, **kwargs)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 提取响应
|
# 提取响应
|
||||||
self.action.substitute_data(self.action.response_json, regex=regex, keys=keys, deps=deps, jp_dict=jp_dict)
|
self.action.substitute_data(self.action.response_json, regex=regex, keys=keys, deps=deps, jp_dict=jp_dict)
|
||||||
|
@ -77,7 +76,7 @@ class TestProjectApi(unittest.TestCase):
|
||||||
f"\ndeps={deps};"
|
f"\ndeps={deps};"
|
||||||
f"\njp_dict={jp_dict}"
|
f"\njp_dict={jp_dict}"
|
||||||
f"\n{err}")
|
f"\n{err}")
|
||||||
|
|
||||||
# 修正断言
|
# 修正断言
|
||||||
expected = self.action.replace_dependent_parameter(expected)
|
expected = self.action.replace_dependent_parameter(expected)
|
||||||
try:
|
try:
|
||||||
|
@ -94,7 +93,7 @@ class TestProjectApi(unittest.TestCase):
|
||||||
# 响应结果及测试结果回写 excel
|
# 响应结果及测试结果回写 excel
|
||||||
excel.write_back(sheet_name=sheet, i=iid, response=response, test_result=result,
|
excel.write_back(sheet_name=sheet, i=iid, response=response, test_result=result,
|
||||||
assert_log=str(self.action.assertions))
|
assert_log=str(self.action.assertions))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls) -> None:
|
def tearDownClass(cls) -> None:
|
||||||
excel.close_excel()
|
excel.close_excel()
|
||||||
|
|
Loading…
Reference in New Issue