mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-31 05:19:38 +08:00
fix: codeview
This commit is contained in:
@@ -1,17 +1,22 @@
|
|||||||
__version__ = "4.0.0-beta"
|
__version__ = "4.0.0-beta"
|
||||||
__description__ = "One-stop solution for HTTP(S) testing."
|
__description__ = "One-stop solution for HTTP(S) testing."
|
||||||
|
|
||||||
|
|
||||||
from httprunner.config import Config
|
from httprunner.config import Config
|
||||||
import platform
|
|
||||||
from httprunner.parser import parse_parameters as Parameters
|
from httprunner.parser import parse_parameters as Parameters
|
||||||
from httprunner.runner import HttpRunner
|
from httprunner.runner import HttpRunner
|
||||||
from httprunner.step import Step
|
from httprunner.step import Step
|
||||||
from httprunner.step_request import RunRequest
|
from httprunner.step_request import RunRequest
|
||||||
from httprunner.step_testcase import RunTestCase
|
|
||||||
from httprunner.step_sql_request import (
|
from httprunner.step_sql_request import (
|
||||||
RunSqlRequest,
|
RunSqlRequest,
|
||||||
StepSqlRequestValidation,
|
|
||||||
StepSqlRequestExtraction,
|
StepSqlRequestExtraction,
|
||||||
|
StepSqlRequestValidation,
|
||||||
|
)
|
||||||
|
from httprunner.step_testcase import RunTestCase
|
||||||
|
from httprunner.step_thrift_request import (
|
||||||
|
RunThriftRequest,
|
||||||
|
StepThriftRequestExtraction,
|
||||||
|
StepThriftRequestValidation,
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
@@ -26,18 +31,7 @@ __all__ = [
|
|||||||
"StepSqlRequestExtraction",
|
"StepSqlRequestExtraction",
|
||||||
"RunTestCase",
|
"RunTestCase",
|
||||||
"Parameters",
|
"Parameters",
|
||||||
|
"RunThriftRequest",
|
||||||
|
"StepThriftRequestValidation",
|
||||||
|
"StepThriftRequestExtraction",
|
||||||
]
|
]
|
||||||
if platform.system() != "Windows":
|
|
||||||
from httprunner.step_thrift_request import (
|
|
||||||
RunThriftRequest,
|
|
||||||
StepThriftRequestValidation,
|
|
||||||
StepThriftRequestExtraction,
|
|
||||||
)
|
|
||||||
|
|
||||||
__all__.extend(
|
|
||||||
[
|
|
||||||
"RunThriftRequest",
|
|
||||||
"StepThriftRequestValidation",
|
|
||||||
"StepThriftRequestExtraction",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -29,17 +29,17 @@ class MethodEnum(Text, Enum):
|
|||||||
|
|
||||||
|
|
||||||
class ProtoType(Enum):
|
class ProtoType(Enum):
|
||||||
pBinary = 1
|
Binary = 1
|
||||||
pCyBinary = 2
|
CyBinary = 2
|
||||||
pCompact = 3
|
Compact = 3
|
||||||
pJson = 4
|
Json = 4
|
||||||
|
|
||||||
|
|
||||||
class TransType(Enum):
|
class TransType(Enum):
|
||||||
tBuffered = 1
|
Buffered = 1
|
||||||
tCyBuffered = 2
|
CyBuffered = 2
|
||||||
tFramed = 3
|
Framed = 3
|
||||||
tCyFramed = 4
|
CyFramed = 4
|
||||||
|
|
||||||
|
|
||||||
# configs for thrift rpc
|
# configs for thrift rpc
|
||||||
@@ -56,8 +56,8 @@ class TConfigThrift(BaseModel):
|
|||||||
ip: Text = "127.0.0.1"
|
ip: Text = "127.0.0.1"
|
||||||
port: int = 9000
|
port: int = 9000
|
||||||
service_name: Text = None
|
service_name: Text = None
|
||||||
proto_type: ProtoType = ProtoType.pBinary
|
proto_type: ProtoType = ProtoType.Binary
|
||||||
trans_type: TransType = TransType.tBuffered
|
trans_type: TransType = TransType.Buffered
|
||||||
|
|
||||||
|
|
||||||
# configs for db
|
# configs for db
|
||||||
|
|||||||
@@ -91,9 +91,11 @@ class SessionRunner(object):
|
|||||||
|
|
||||||
def with_thrift_client(self, thrift_client) -> "SessionRunner":
|
def with_thrift_client(self, thrift_client) -> "SessionRunner":
|
||||||
self.thrift_client = thrift_client
|
self.thrift_client = thrift_client
|
||||||
|
return self
|
||||||
|
|
||||||
def with_db_engine(self, db_engine):
|
def with_db_engine(self, db_engine) -> "SessionRunner":
|
||||||
self.db_engine = db_engine
|
self.db_engine = db_engine
|
||||||
|
return self
|
||||||
|
|
||||||
def __parse_config(self, param: Dict = None) -> None:
|
def __parse_config(self, param: Dict = None) -> None:
|
||||||
# parse config variables
|
# parse config variables
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
import platform
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from httprunner.models import StepResult, TRequest, TStep, TestCase
|
|
||||||
from httprunner.runner import HttpRunner
|
|
||||||
from httprunner.step_request import (
|
from httprunner.step_request import (
|
||||||
RequestWithOptionalArgs,
|
RequestWithOptionalArgs,
|
||||||
StepRequestExtraction,
|
StepRequestExtraction,
|
||||||
StepRequestValidation,
|
StepRequestValidation,
|
||||||
)
|
)
|
||||||
from httprunner.step_testcase import StepRefCase
|
|
||||||
from httprunner.step_sql_request import (
|
from httprunner.step_sql_request import (
|
||||||
RunSqlRequest,
|
RunSqlRequest,
|
||||||
StepSqlRequestValidation,
|
|
||||||
StepSqlRequestExtraction,
|
StepSqlRequestExtraction,
|
||||||
|
StepSqlRequestValidation,
|
||||||
|
)
|
||||||
|
from httprunner.step_testcase import StepRefCase
|
||||||
|
from httprunner.step_thrift_request import (
|
||||||
|
RunThriftRequest,
|
||||||
|
StepThriftRequestExtraction,
|
||||||
|
StepThriftRequestValidation,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -27,60 +29,9 @@ class Step(object):
|
|||||||
RunSqlRequest,
|
RunSqlRequest,
|
||||||
StepSqlRequestValidation,
|
StepSqlRequestValidation,
|
||||||
StepSqlRequestExtraction,
|
StepSqlRequestExtraction,
|
||||||
|
RunThriftRequest,
|
||||||
|
StepThriftRequestValidation,
|
||||||
|
StepThriftRequestExtraction,
|
||||||
],
|
],
|
||||||
):
|
):
|
||||||
self.__step = step
|
super().__init__(step)
|
||||||
|
|
||||||
@property
|
|
||||||
def request(self) -> TRequest:
|
|
||||||
return self.__step.struct().request
|
|
||||||
|
|
||||||
@property
|
|
||||||
def testcase(self) -> TestCase:
|
|
||||||
return self.__step.struct().testcase
|
|
||||||
|
|
||||||
@property
|
|
||||||
def retry_times(self) -> int:
|
|
||||||
return self.__step.struct().retry_times
|
|
||||||
|
|
||||||
@property
|
|
||||||
def retry_interval(self) -> int:
|
|
||||||
return self.__step.struct().retry_interval
|
|
||||||
|
|
||||||
def struct(self) -> TStep:
|
|
||||||
return self.__step.struct()
|
|
||||||
|
|
||||||
def name(self) -> str:
|
|
||||||
return self.__step.name()
|
|
||||||
|
|
||||||
def type(self) -> str:
|
|
||||||
return self.__step.type()
|
|
||||||
|
|
||||||
def run(self, runner: HttpRunner) -> StepResult:
|
|
||||||
return self.__step.run(runner)
|
|
||||||
|
|
||||||
|
|
||||||
if platform.system() != "Windows":
|
|
||||||
from httprunner.step_thrift_request import (
|
|
||||||
RunThriftRequest,
|
|
||||||
StepThriftRequestValidation,
|
|
||||||
StepThriftRequestExtraction,
|
|
||||||
)
|
|
||||||
|
|
||||||
class Step(Step):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
step: Union[
|
|
||||||
StepRequestValidation,
|
|
||||||
StepRequestExtraction,
|
|
||||||
RequestWithOptionalArgs,
|
|
||||||
StepRefCase,
|
|
||||||
RunSqlRequest,
|
|
||||||
StepSqlRequestValidation,
|
|
||||||
StepSqlRequestExtraction,
|
|
||||||
RunThriftRequest,
|
|
||||||
StepThriftRequestValidation,
|
|
||||||
StepThriftRequestExtraction,
|
|
||||||
],
|
|
||||||
):
|
|
||||||
super().__init__(step)
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ from httprunner.step_request import (
|
|||||||
StepRequestExtraction,
|
StepRequestExtraction,
|
||||||
StepRequestValidation,
|
StepRequestValidation,
|
||||||
)
|
)
|
||||||
from httprunner.database.engine import DBEngine
|
|
||||||
from httprunner.exceptions import SqlMethodNotSupport
|
from httprunner.exceptions import SqlMethodNotSupport
|
||||||
|
|
||||||
|
|
||||||
@@ -52,6 +51,8 @@ def run_step_sql_request(runner: HttpRunner, step: TStep) -> StepResult:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not runner.db_engine:
|
if not runner.db_engine:
|
||||||
|
from httprunner.database.engine import DBEngine
|
||||||
|
|
||||||
runner.db_engine = DBEngine(
|
runner.db_engine = DBEngine(
|
||||||
f'mysql+pymysql://{parsed_request_dict["db_config"]["user"]}:'
|
f'mysql+pymysql://{parsed_request_dict["db_config"]["user"]}:'
|
||||||
f'{parsed_request_dict["db_config"]["password"]}@{parsed_request_dict["db_config"]["ip"]}:'
|
f'{parsed_request_dict["db_config"]["password"]}@{parsed_request_dict["db_config"]["ip"]}:'
|
||||||
|
|||||||
@@ -1,21 +1,26 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import time
|
import time
|
||||||
from typing import Text, Union
|
from typing import Text, Union
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from httprunner import utils
|
from httprunner import utils
|
||||||
from httprunner.exceptions import ValidationFailure
|
from httprunner.exceptions import ValidationFailure
|
||||||
from httprunner.models import IStep, StepResult, TStep, ProtoType, TransType
|
from httprunner.models import (
|
||||||
|
IStep,
|
||||||
|
ProtoType,
|
||||||
|
StepResult,
|
||||||
|
TStep,
|
||||||
|
TThriftRequest,
|
||||||
|
TransType,
|
||||||
|
)
|
||||||
|
from httprunner.response import ThriftResponseObject
|
||||||
from httprunner.runner import HttpRunner
|
from httprunner.runner import HttpRunner
|
||||||
from httprunner.step_request import (
|
from httprunner.step_request import (
|
||||||
call_hooks,
|
|
||||||
StepRequestExtraction,
|
StepRequestExtraction,
|
||||||
StepRequestValidation,
|
StepRequestValidation,
|
||||||
|
call_hooks,
|
||||||
)
|
)
|
||||||
from httprunner.models import TThriftRequest
|
|
||||||
from httprunner.response import ThriftResponseObject
|
|
||||||
|
|
||||||
from httprunner.thrift.thrift_client import ThriftClient
|
|
||||||
|
|
||||||
|
|
||||||
def run_step_thrift_request(runner: HttpRunner, step: TStep) -> StepResult:
|
def run_step_thrift_request(runner: HttpRunner, step: TStep) -> StepResult:
|
||||||
@@ -71,6 +76,8 @@ def run_step_thrift_request(runner: HttpRunner, step: TStep) -> StepResult:
|
|||||||
if not runner.thrift_client:
|
if not runner.thrift_client:
|
||||||
runner.thrift_client = parsed_request_dict["thrift_client"]
|
runner.thrift_client = parsed_request_dict["thrift_client"]
|
||||||
if not runner.thrift_client:
|
if not runner.thrift_client:
|
||||||
|
from httprunner.thrift.thrift_client import ThriftClient
|
||||||
|
|
||||||
runner.thrift_client = ThriftClient(
|
runner.thrift_client = ThriftClient(
|
||||||
thrift_file=parsed_request_dict["idl_path"],
|
thrift_file=parsed_request_dict["idl_path"],
|
||||||
service_name=parsed_request_dict["service_name"],
|
service_name=parsed_request_dict["service_name"],
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
import platform
|
||||||
import enum
|
import enum
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from loguru import logger
|
|
||||||
import thriftpy2
|
import thriftpy2
|
||||||
|
from loguru import logger
|
||||||
from thriftpy2.protocol import (
|
from thriftpy2.protocol import (
|
||||||
TBinaryProtocolFactory,
|
TBinaryProtocolFactory,
|
||||||
TCompactProtocolFactory,
|
TCompactProtocolFactory,
|
||||||
@@ -18,23 +19,22 @@ from thriftpy2.transport import (
|
|||||||
TCyFramedTransportFactory,
|
TCyFramedTransportFactory,
|
||||||
TFramedTransportFactory,
|
TFramedTransportFactory,
|
||||||
)
|
)
|
||||||
from thriftpy2.utils import deserialize
|
|
||||||
|
|
||||||
from httprunner.thrift.data_convertor import json2thrift, thrift2json, thrift2dict
|
from httprunner.thrift.data_convertor import json2thrift, thrift2dict
|
||||||
|
|
||||||
|
|
||||||
class ProtoType(enum.Enum):
|
class ProtoType(enum.Enum):
|
||||||
pBinary = 1
|
Binary = 1
|
||||||
pCyBinary = 2
|
CyBinary = 2
|
||||||
pCompact = 3
|
Compact = 3
|
||||||
pJson = 4
|
Json = 4
|
||||||
|
|
||||||
|
|
||||||
class TransType(enum.Enum):
|
class TransType(enum.Enum):
|
||||||
tBuffered = 1
|
Buffered = 1
|
||||||
tCyBuffered = 2
|
CyBuffered = 2
|
||||||
tFramed = 3
|
Framed = 3
|
||||||
tCyFramed = 4
|
CyFramed = 4
|
||||||
|
|
||||||
|
|
||||||
class RequestFormat(enum.Enum):
|
class RequestFormat(enum.Enum):
|
||||||
@@ -43,24 +43,24 @@ class RequestFormat(enum.Enum):
|
|||||||
|
|
||||||
|
|
||||||
def get_proto_factory(proto_type):
|
def get_proto_factory(proto_type):
|
||||||
if proto_type == ProtoType.pBinary:
|
if proto_type == ProtoType.Binary:
|
||||||
return TBinaryProtocolFactory()
|
return TBinaryProtocolFactory()
|
||||||
if proto_type == ProtoType.pCyBinary:
|
if proto_type == ProtoType.CyBinary:
|
||||||
return TCyBinaryProtocolFactory()
|
return TCyBinaryProtocolFactory()
|
||||||
if proto_type == ProtoType.pCompact:
|
if proto_type == ProtoType.Compact:
|
||||||
return TCompactProtocolFactory()
|
return TCompactProtocolFactory()
|
||||||
if proto_type == ProtoType.pJson:
|
if proto_type == ProtoType.Json:
|
||||||
return TJSONProtocolFactory()
|
return TJSONProtocolFactory()
|
||||||
|
|
||||||
|
|
||||||
def get_trans_factory(trans_type):
|
def get_trans_factory(trans_type):
|
||||||
if trans_type == TransType.tBuffered:
|
if trans_type == TransType.Buffered:
|
||||||
return TBufferedTransportFactory()
|
return TBufferedTransportFactory()
|
||||||
if trans_type == TransType.tCyBuffered:
|
if trans_type == TransType.CyBuffered:
|
||||||
return TCyBufferedTransportFactory()
|
return TCyBufferedTransportFactory()
|
||||||
if trans_type == TransType.tFramed:
|
if trans_type == TransType.Framed:
|
||||||
return TFramedTransportFactory()
|
return TFramedTransportFactory()
|
||||||
if trans_type == TransType.tCyFramed:
|
if trans_type == TransType.CyFramed:
|
||||||
return TCyFramedTransportFactory()
|
return TCyFramedTransportFactory()
|
||||||
|
|
||||||
|
|
||||||
@@ -73,8 +73,8 @@ class ThriftClient(object):
|
|||||||
port,
|
port,
|
||||||
include_dirs=None,
|
include_dirs=None,
|
||||||
timeout=3000,
|
timeout=3000,
|
||||||
proto_type=ProtoType.pCyBinary,
|
proto_type=ProtoType.CyBinary,
|
||||||
trans_type=TransType.tCyBuffered,
|
trans_type=TransType.CyBuffered,
|
||||||
):
|
):
|
||||||
self.thrift_file = thrift_file
|
self.thrift_file = thrift_file
|
||||||
self.include_dirs = include_dirs
|
self.include_dirs = include_dirs
|
||||||
@@ -84,6 +84,7 @@ class ThriftClient(object):
|
|||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.proto_type = proto_type
|
self.proto_type = proto_type
|
||||||
self.trans_type = trans_type
|
self.trans_type = trans_type
|
||||||
|
assert platform.system() != "Windows", "thrift not support Windows for now"
|
||||||
try:
|
try:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"init thrift module: thrift_file=%s, module_name=%s",
|
"init thrift module: thrift_file=%s, module_name=%s",
|
||||||
|
|||||||
Reference in New Issue
Block a user