220808
This commit is contained in:
parent
644f9a3762
commit
77c3939c27
|
@ -11,12 +11,9 @@ from Base.Class.Logger import *
|
||||||
|
|
||||||
def reparse(regexp, string):
|
def reparse(regexp, string):
|
||||||
import re
|
import re
|
||||||
if isinstance(regexp, tuple):
|
mut = isinstance(regexp, tuple)
|
||||||
reg = str(regexp[0])
|
reg = [str(regexp), str(regexp[0])][mut]
|
||||||
flg = eval('re.' + str(regexp[1]).upper())
|
flg = [0, eval('re.%s' % str(regexp[1]).upper())][mut]
|
||||||
else:
|
|
||||||
reg = str(regexp)
|
|
||||||
flg = 0
|
|
||||||
if reg in ['', 'trim']:
|
if reg in ['', 'trim']:
|
||||||
return ReText(string.strip())
|
return ReText(string.strip())
|
||||||
else:
|
else:
|
||||||
|
@ -38,7 +35,7 @@ class ReList(list):
|
||||||
r = super().__getitem__(item)
|
r = super().__getitem__(item)
|
||||||
if isinstance(r, (list, tuple, set)):
|
if isinstance(r, (list, tuple, set)):
|
||||||
return __class__(r)
|
return __class__(r)
|
||||||
elif isinstance(r, (dict, )):
|
elif isinstance(r, (dict,)):
|
||||||
return ReDict(r)
|
return ReDict(r)
|
||||||
else:
|
else:
|
||||||
return ReText(r)
|
return ReText(r)
|
||||||
|
@ -64,7 +61,7 @@ class ReDict(dict):
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
if item in self:
|
if item in self:
|
||||||
r = super().__getitem__(item)
|
r = super().__getitem__(item)
|
||||||
if isinstance(r, (dict, )):
|
if isinstance(r, (dict,)):
|
||||||
return __class__(r)
|
return __class__(r)
|
||||||
elif isinstance(r, (list, tuple, set)):
|
elif isinstance(r, (list, tuple, set)):
|
||||||
return ReList(r)
|
return ReList(r)
|
||||||
|
@ -220,9 +217,6 @@ class TestCase:
|
||||||
self.d = data['TestData']['views']
|
self.d = data['TestData']['views']
|
||||||
self.c = data['TestCase']['views']
|
self.c = data['TestCase']['views']
|
||||||
|
|
||||||
# print(self.h.where((self.h['Name'] == 'HTTP2'), inplace=False).dropna(how='all').reset_index(drop=True, inplace=False).loc[0].to_dict())
|
|
||||||
# exit()
|
|
||||||
|
|
||||||
self._set_levels(testlves)
|
self._set_levels(testlves)
|
||||||
self._set_request_mode(self.m)
|
self._set_request_mode(self.m)
|
||||||
|
|
||||||
|
@ -256,7 +250,7 @@ class TestCase:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _match_bool(value=None):
|
def _match_bool(value=None):
|
||||||
return value in ['是', '开启', '打开', 'True', 'true', 'TRUE', True, 'Yes', 'yes', 'YES', 'Y', 'y', '1', 1, 1.0]
|
return value in ['是', '开启', '打开', 'True', 'true', 'TRUE', True, 'Yes', 'yes', 'YES', 'Y', 'y', '1', 1, 1.0]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _match_mode(value=None):
|
def _match_mode(value=None):
|
||||||
return value in ['会话模式', 'Session', 'session']
|
return value in ['会话模式', 'Session', 'session']
|
||||||
|
@ -309,7 +303,8 @@ class TestCase:
|
||||||
continue
|
continue
|
||||||
data[k] = self._sub_variable(text=data[k], vars_dict=vars_dict)
|
data[k] = self._sub_variable(text=data[k], vars_dict=vars_dict)
|
||||||
return data
|
return data
|
||||||
if isinstance(data, str): return self._sub_variable(data, vars_dict=vars_dict)
|
if isinstance(data, str):
|
||||||
|
return self._sub_variable(data, vars_dict=vars_dict)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -327,24 +322,27 @@ class TestCase:
|
||||||
return str(text)
|
return str(text)
|
||||||
|
|
||||||
def test_unit(self, data):
|
def test_unit(self, data):
|
||||||
locals().setdefault('h', self.h.where((self.h['Name'] == data['HTTPChannel']), inplace=False).dropna(how='all').reset_index(drop=True, inplace=False).loc[0].to_dict())
|
http = self.h.where((self.h['Name'] == data['HTTPChannel']), inplace=False).dropna(how='all').reset_index(drop=True, inplace=False).loc[0].to_dict()
|
||||||
res_kwargs = {
|
res_kwargs = {
|
||||||
'method': data['HTTPMethod'],
|
'method': data['HTTPMethod'],
|
||||||
'url': self._sub_variable_auto((locals().get('h')['HostWithScheme'] or '') + (data['HTTPUri'] or '/'), [self._g, self._l]),
|
'url': self._sub_variable_auto((http['HostWithScheme'] or '') + (data['HTTPUri'] or '/'), [self._g, self._l]),
|
||||||
'query': self._sub_variable_auto(auto_decode(data['HTTPQuery']), [self._g, self._l]),
|
'query': self._sub_variable_auto(auto_decode(data['HTTPQuery']), [self._g, self._l]),
|
||||||
'data': None,
|
'data': None,
|
||||||
'json': None,
|
'json': None,
|
||||||
'file': None,
|
'file': None,
|
||||||
'header': {},
|
'header': {},
|
||||||
'cookie': self._sub_variable_auto(auto_decode(data['HTTPCookie']), [self._g, self._l]),
|
'cookie': self._sub_variable_auto(
|
||||||
'auth': None,
|
auto_decode(data['HTTPCookie']),
|
||||||
'timeout': 60,
|
[self._g, self._l]
|
||||||
'proxy': None,
|
),
|
||||||
|
'auth': None,
|
||||||
|
'timeout': 60,
|
||||||
|
'proxy': None,
|
||||||
'auto_redirect': self._match_bool(data['HTTPRedirect']),
|
'auto_redirect': self._match_bool(data['HTTPRedirect']),
|
||||||
'ignore_cert_error': False,
|
'ignore_cert_error': False,
|
||||||
'debug': True
|
'debug': True
|
||||||
}
|
}
|
||||||
res_kwargs['header'].update((auto_decode(locals().get('h')['DefaultHeader']) or {}))
|
res_kwargs['header'].update((auto_decode(http['DefaultHeader']) or {}))
|
||||||
res_kwargs['header'].update((self._sub_variable_auto(auto_decode(data['HTTPHeader']), [self._g, self._l]) or {}))
|
res_kwargs['header'].update((self._sub_variable_auto(auto_decode(data['HTTPHeader']), [self._g, self._l]) or {}))
|
||||||
match self._match_parm_type(data['HTTPParamType']):
|
match self._match_parm_type(data['HTTPParamType']):
|
||||||
case 10:
|
case 10:
|
||||||
|
@ -356,21 +354,24 @@ class TestCase:
|
||||||
res_kwargs['file'] = locals().setdefault('f', self._sub_variable_auto(auto_decode(
|
res_kwargs['file'] = locals().setdefault('f', self._sub_variable_auto(auto_decode(
|
||||||
data['HTTPParamOfFile']))) and {k: open(os.path.abspath(os.path.join(self.dirs, './%s' % v)), 'rb') for k, v in locals().get('f').items()}
|
data['HTTPParamOfFile']))) and {k: open(os.path.abspath(os.path.join(self.dirs, './%s' % v)), 'rb') for k, v in locals().get('f').items()}
|
||||||
res = self.http.http(**res_kwargs)
|
res = self.http.http(**res_kwargs)
|
||||||
locals().setdefault('_Status', ReText(res['status'] or ''))
|
for var_name, var_value in {
|
||||||
locals().setdefault('_Reason', ReText(res['reason'] or ''))
|
'_Status': ReText(res['status'] or ''),
|
||||||
locals().setdefault('_Header', ReDict(res['header'] or {}).update({'_': yaml_encode(dict(res['header'] or {}))}))
|
'_Reason': ReText(res['reason'] or ''),
|
||||||
locals().setdefault('_Cookie', ReDict(res['cookie'] or {}).update({'_': '; '.join([k + '=' + (v or '') for k, v in dict(res['cookie'] or {}).items()])}))
|
'_Header': ReDict(res['header'] or {}).update({'_': yaml_encode(dict(res['header'] or {}))}),
|
||||||
locals().setdefault('_Body', ReText(res['text'] or ''))
|
'_Cookie': ReDict(res['cookie'] or {}).update({'_': '; '.join([k + '=' + (v or '') for k, v in dict(res['cookie'] or {}).items()])}),
|
||||||
locals().setdefault('_Json', ReDict(res['json'] or {}))
|
'_Body': ReText(res['text'] or ''),
|
||||||
|
'_Json': ReDict(res['json'] or {}),
|
||||||
|
json_encode(None): None,
|
||||||
|
json_encode(bool(0)): bool(0),
|
||||||
|
json_encode(bool(1)): bool(1)
|
||||||
|
}.items():
|
||||||
|
locals().setdefault(var_name, var_value)
|
||||||
for k, v in (auto_decode(data['HTTPExtract']) or {}).items():
|
for k, v in (auto_decode(data['HTTPExtract']) or {}).items():
|
||||||
d = re.findall('^([0-9A-Za-z_]+).*?', v)[0]
|
d = re.findall('^([0-9A-Za-z_]+).*?', v)[0]
|
||||||
self._g[str(k)] = str(eval('_' + v.replace(d, d.title(), 1)))
|
self._g[str(k)] = str(eval('_' + v.replace(d, d.title(), 1)))
|
||||||
|
|
||||||
expect = self._to_string(data['HTTPAssertStatus'])
|
expect = self._to_string(data['HTTPAssertStatus'])
|
||||||
if expect:
|
if expect:
|
||||||
locals().setdefault('null', None)
|
|
||||||
locals().setdefault('true', True)
|
|
||||||
locals().setdefault('false', False)
|
|
||||||
opers = [" == ", " != ", " >= ", " <= ", " > ", " < ", " in ", " not in "]
|
opers = [" == ", " != ", " >= ", " <= ", " > ", " < ", " in ", " not in "]
|
||||||
opers_flag = 0
|
opers_flag = 0
|
||||||
for v in opers:
|
for v in opers:
|
||||||
|
@ -378,7 +379,7 @@ class TestCase:
|
||||||
opers_flag = 1
|
opers_flag = 1
|
||||||
break
|
break
|
||||||
if opers_flag:
|
if opers_flag:
|
||||||
contrast = list(filter(lambda x: x,expect.split("\n")))
|
contrast = list(filter(lambda x: x, expect.split("\n")))
|
||||||
for contr in contrast:
|
for contr in contrast:
|
||||||
exec('assert ' + self._sub_variable_auto(contr).replace('$', str(res['status'])))
|
exec('assert ' + self._sub_variable_auto(contr).replace('$', str(res['status'])))
|
||||||
else:
|
else:
|
||||||
|
@ -389,9 +390,6 @@ class TestCase:
|
||||||
raise AssertionError(str(expect) + ' == ' + str(actual))
|
raise AssertionError(str(expect) + ' == ' + str(actual))
|
||||||
# sys.stderr.write()
|
# sys.stderr.write()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test(self, index):
|
def test(self, index):
|
||||||
# print(view_case.loc[index])
|
# print(view_case.loc[index])
|
||||||
main_case = dict(self.c.loc[index].to_dict())
|
main_case = dict(self.c.loc[index].to_dict())
|
||||||
|
|
31
main3.py
31
main3.py
|
@ -1,5 +1,26 @@
|
||||||
def to_string(text):
|
str0 = '''"it in the ..." in $['content']'''
|
||||||
if text is None:
|
|
||||||
return ''
|
str1 = '''"it in the ..." in $['content']'''
|
||||||
return str(text)
|
str2 = '''$['content'] == "ha in the end."'''
|
||||||
exec('assert 1 == 2')
|
str3 = '''"it in the ..." in $'''
|
||||||
|
str4 = """$w.dasfd[9][0] in 'it in the ...'"""
|
||||||
|
str5 = '''$.flag == true'''
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
str41 = """$w.dasfd[9][0] in 'it in the ...'"""
|
||||||
|
str42 = '''$w.dasfd[9][0] in "it in the ..."'''
|
||||||
|
str43 = """$w.dasfd['a']['vf'] in 'it in the ...'"""
|
||||||
|
str44 = """$w.dasfd['a']['vf in '] in true"""
|
||||||
|
str45 = """$null in true"""
|
||||||
|
str46 = "$w.dasfd['a']['vf in '] in \"true\""
|
||||||
|
|
||||||
|
|
||||||
|
s = str45
|
||||||
|
print(re.findall('[\"].*?[\"].*?[\s]*( in )[\s]*', s))
|
||||||
|
print(re.findall('[\'].*?[\'].*?[\s]*( in )[\s]*', s))
|
||||||
|
print(re.findall('[\s]*( in )[\s]*.*?[\"].*?[\"]', s))
|
||||||
|
print(re.findall('[\s]*( in )[\s]*.*?[\'].*?[\']', s))
|
||||||
|
# ?
|
||||||
|
# print(re.compile(' in ').sub(' IN ', str1))
|
||||||
|
|
Loading…
Reference in New Issue