mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-21 16:22:17 +08:00
feat: add ConfigThrift for thrift rpc
This commit is contained in:
@@ -1,60 +1,79 @@
|
|||||||
import inspect
|
import inspect
|
||||||
from typing import Text
|
from typing import Text
|
||||||
|
|
||||||
from httprunner.models import TConfig
|
from httprunner.models import TConfig, TConfigThrift
|
||||||
|
|
||||||
|
|
||||||
class Config(object):
|
class ConfigThrift(object):
|
||||||
def __init__(self, name: Text):
|
|
||||||
self.__name = name
|
|
||||||
self.__variables = {}
|
|
||||||
self.__base_url = ""
|
|
||||||
self.__verify = False
|
|
||||||
self.__export = []
|
|
||||||
self.__weight = 1
|
|
||||||
|
|
||||||
caller_frame = inspect.stack()[1]
|
def __init__(self, config: TConfig) -> None:
|
||||||
self.__path = caller_frame.filename
|
self.__config = config
|
||||||
|
self.__config.thrift = TConfigThrift()
|
||||||
|
|
||||||
@property
|
def psm(self, psm: Text) -> "ConfigThrift":
|
||||||
def name(self) -> Text:
|
self.__config.thrift.psm = psm
|
||||||
return self.__name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def path(self) -> Text:
|
|
||||||
return self.__path
|
|
||||||
|
|
||||||
@property
|
|
||||||
def weight(self) -> int:
|
|
||||||
return self.__weight
|
|
||||||
|
|
||||||
def variables(self, **variables) -> "Config":
|
|
||||||
self.__variables.update(variables)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def base_url(self, base_url: Text) -> "Config":
|
def env(self, env: Text) -> "ConfigThrift":
|
||||||
self.__base_url = base_url
|
self.__config.thrift.env = env
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def verify(self, verify: bool) -> "Config":
|
def cluster(self, cluster: Text) -> "ConfigThrift":
|
||||||
self.__verify = verify
|
self.__config.thrift.cluster = cluster
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def export(self, *export_var_name: Text) -> "Config":
|
def target(self, target: Text) -> "ConfigThrift":
|
||||||
self.__export.extend(export_var_name)
|
self.__config.thrift.target = target
|
||||||
return self
|
|
||||||
|
|
||||||
def locust_weight(self, weight: int) -> "Config":
|
|
||||||
self.__weight = weight
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def struct(self) -> TConfig:
|
def struct(self) -> TConfig:
|
||||||
return TConfig(
|
return self.__config
|
||||||
name=self.__name,
|
|
||||||
base_url=self.__base_url,
|
|
||||||
verify=self.__verify,
|
class Config(object):
|
||||||
variables=self.__variables,
|
|
||||||
export=list(set(self.__export)),
|
def __init__(self, name: Text) -> None:
|
||||||
path=self.__path,
|
caller_frame = inspect.stack()[1]
|
||||||
weight=self.__weight,
|
self.__config = TConfig(
|
||||||
|
name=name,
|
||||||
|
path=caller_frame.filename
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> Text:
|
||||||
|
return self.__config.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self) -> Text:
|
||||||
|
return self.__config.path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def weight(self) -> int:
|
||||||
|
return self.__config.weight
|
||||||
|
|
||||||
|
def variables(self, **variables) -> "Config":
|
||||||
|
self.__config.variables.update(variables)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def base_url(self, base_url: Text) -> "Config":
|
||||||
|
self.__config.base_url = base_url
|
||||||
|
return self
|
||||||
|
|
||||||
|
def verify(self, verify: bool) -> "Config":
|
||||||
|
self.__config.verify = verify
|
||||||
|
return self
|
||||||
|
|
||||||
|
def export(self, *export_var_name: Text) -> "Config":
|
||||||
|
self.__config.export.extend(export_var_name)
|
||||||
|
self.__config.export = list(set(self.__config.export))
|
||||||
|
return self
|
||||||
|
|
||||||
|
def locust_weight(self, weight: int) -> "Config":
|
||||||
|
self.__config.weight = weight
|
||||||
|
return self
|
||||||
|
|
||||||
|
def struct(self) -> TConfig:
|
||||||
|
return self.__config
|
||||||
|
|
||||||
|
def thrift(self) -> ConfigThrift:
|
||||||
|
return ConfigThrift(self.__config)
|
||||||
|
|||||||
@@ -28,6 +28,16 @@ class MethodEnum(Text, Enum):
|
|||||||
PATCH = "PATCH"
|
PATCH = "PATCH"
|
||||||
|
|
||||||
|
|
||||||
|
# configs for thrift rpc
|
||||||
|
class TConfigThrift(BaseModel):
|
||||||
|
psm: Text = None
|
||||||
|
env: Text = None
|
||||||
|
cluster: Text = None
|
||||||
|
target: Text = None
|
||||||
|
include_dirs: List[Text] = None
|
||||||
|
thrift_client: Any = None
|
||||||
|
|
||||||
|
|
||||||
class TConfig(BaseModel):
|
class TConfig(BaseModel):
|
||||||
name: Name
|
name: Name
|
||||||
verify: Verify = False
|
verify: Verify = False
|
||||||
@@ -40,6 +50,7 @@ class TConfig(BaseModel):
|
|||||||
export: Export = []
|
export: Export = []
|
||||||
path: Text = None
|
path: Text = None
|
||||||
weight: int = 1
|
weight: int = 1
|
||||||
|
thrift: TConfigThrift = None
|
||||||
|
|
||||||
|
|
||||||
class TRequest(BaseModel):
|
class TRequest(BaseModel):
|
||||||
|
|||||||
Reference in New Issue
Block a user