优化部分代码

This commit is contained in:
谈林海 2023-08-07 09:40:43 +08:00
parent 099f747f1b
commit b5e78d3b5e
3 changed files with 4 additions and 15 deletions

View File

@ -101,7 +101,7 @@ if not db_config:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def collection(): def core():
class Core: class Core:
def __init__(self): def __init__(self):
self.requests = RestClient() self.requests = RestClient()
@ -113,8 +113,3 @@ def collection():
yield Core() yield Core()
@pytest.fixture()
def core(collection):
yield collection

View File

@ -52,16 +52,16 @@ class DataHandler:
if '{{' in value and '}}' in value and 'int.' not in value and 'str.' not in value: if '{{' in value and '}}' in value and 'int.' not in value and 'str.' not in value:
func = value[value.find('{') + 2:value.find('}')] func = value[value.find('{') + 2:value.find('}')]
return value.replace('{{%s}}' % f'{func}', str(Mock(func)())) return value.replace('{{%s}}' % func, str(Mock(func)()))
elif '$cache.' in value: elif '$cache.' in value:
cache_name = value[value.find('.') + 1:] cache_name = value[value.find('.') + 1:]
return self.cache_data.get(cache_name, None) return self.cache_data.get(cache_name, None)
elif 'int.' in value: elif 'int.' in value:
func = value[value.find('{') + 2:value.find('}')] func = value[value.find('{') + 2:value.find('}')]
return int(value.replace('{{%s}}' % f'{func}', str(Mock(func[func.find('.') + 1:])()))) return int(value.replace('{{%s}}' % func, str(Mock(func[func.find('.') + 1:])())))
elif 'str.' in value: elif 'str.' in value:
func = value[value.find('{') + 2:value.find('}')] func = value[value.find('{') + 2:value.find('}')]
return str(value.replace('{{%s}}' % f'{func}', str(Mock(func[func.find('.') + 1:])()))) return str(value.replace('{{%s}}' % func, str(Mock(func[func.find('.') + 1:])())))
else: else:
return value return value

View File

@ -44,12 +44,6 @@ class RestClient:
self.cookies, self.token = Authentication.cookie_token() self.cookies, self.token = Authentication.cookie_token()
self.client = httpx.Client(cookies=self.cookies, timeout=30, verify=False) self.client = httpx.Client(cookies=self.cookies, timeout=30, verify=False)
def __del__(self):
"""
显式关闭会话
"""
self.client.close()
def res_log(func): def res_log(func):
@wraps(func) @wraps(func)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):