Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
test_platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Wallen姚文辉
test_platform
Commits
0f9cf91b
Commit
0f9cf91b
authored
Jun 17, 2024
by
Wallen姚文辉
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口测试报告重构
parent
a759893b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
25 deletions
+81
-25
Tool.py
controller/Tool.py
+54
-25
test.py
test.py
+27
-0
No files found.
controller/Tool.py
View file @
0f9cf91b
...
...
@@ -19,6 +19,8 @@ db=server.db
tool
=
Blueprint
(
"tools"
,
__name__
,
url_prefix
=
'/tool'
)
jiraAddress
=
"http://jira.galaxy-immi.com"
apifox_token
=
None
def
getheader
(
id_
):
result
=
db
.
session
.
query
(
User
.
jira_account
,
User
.
jira_password
)
.
filter_by
(
id
=
id_
)
.
first
()
db
.
session
.
close
()
...
...
@@ -427,34 +429,61 @@ def test():
return
jsonify
({
"code"
:
200
,
"message"
:
"请求成功"
,
"data"
:
a
}),
200
# @tool.route('/testport/getapitestinfo', methods=["POST"])
# def getapitestinfo():
# info=request.json.get("data")
# try:
# runinfo={"运行列表":[]}
# soup=BeautifulSoup(info,"html.parser")
# a=soup.find(class_="container")
# path=lambda x:f'div[class="card"]>div[class="card-body"]>div[class="row"]>div:-soup-contains("{x}")+div'
# onlyinfolist=["测试场景","运行时间","总耗时","总返回数据","接口请求耗时","平均接口请求耗时","通过率","失败率","未测率"]
# twoinfolist=["循环数","HTTP 接口请求数","断言数"]
# [runinfo.update({i:soup.select(path(i))[0].text}) for i in onlyinfolist]
# [runinfo.update({i:[soup.select(path(i))[0].text,soup.select(path(i)+'+div')[0].text]}) for i in twoinfolist]
# for each in a.select("div[class='']>div[class='collapse']>div[class='']"):
# this={"step":[]}
# k=each.find_all('div',recursive=False)
# this["name"]=k[0].text.strip()
# for item in k[1].find_all('div',recursive=False):
# stepinfo={"断言详情":[]}
# stepinfo["name"]=item.find('h5').text.strip()
# onlyinfolist=["Method","URL","耗时","返回数据","HTTP 状态码","断言通过数","断言失败数"]
# path=lambda x:f'div[class="card-body"]>div>div[class="row"]>div:-soup-contains("{x}")+div'
# [stepinfo.update({i:item.select(path(i))[0].text}) for i in onlyinfolist]
# stepinfo["断言详情"].append(list(map(lambda x:x.text.strip(),item.select('div[class="card-body"]>div>div[class="row"]>div:-soup-contains("断言详情")+div>table>tbody>tr>td'))))
# this["step"].append(stepinfo)
# runinfo["运行列表"].append(this)
# return jsonify({"code": 200, "message": "请求成功","data":runinfo}),200
# except:
# return jsonify({"code": 403, "message": "文件内容有误,请确认"}),403
def
updateapitoken
():
user
,
password
=
'wallen.ywh@galaxyoversea.com'
,
'ywh940509'
global
apifox_token
apifox_token
=
requests
.
post
(
'https://api.apifox.com/api/v1/login?locale=zh-CN'
,
json
=
{
"account"
:
user
,
"loginType"
:
"EmailPassword"
,
"password"
:
password
})
.
json
()
.
get
(
"data"
)
.
get
(
"accessToken"
)
@
tool
.
route
(
'/testport/getapitestinfo'
,
methods
=
[
"POST"
])
def
getapitestinfo
():
info
=
request
.
json
.
get
(
"data"
)
url
=
request
.
json
.
get
(
"url"
)
.
strip
()
global
apifox_token
apifox_token
or
updateapitoken
()
infolist
=
url
.
split
(
'/'
)
project_id
,
caseid
=
infolist
[
-
4
],
infolist
[
-
1
]
try
:
runinfo
=
{
"运行列表"
:[]}
soup
=
BeautifulSoup
(
info
,
"html.parser"
)
a
=
soup
.
find
(
class_
=
"container"
)
path
=
lambda
x
:
f
'div[class="card"]>div[class="card-body"]>div[class="row"]>div:-soup-contains("{x}")+div'
onlyinfolist
=
[
"测试场景"
,
"运行时间"
,
"总耗时"
,
"总返回数据"
,
"接口请求耗时"
,
"平均接口请求耗时"
,
"通过率"
,
"失败率"
,
"未测率"
]
twoinfolist
=
[
"循环数"
,
"HTTP 接口请求数"
,
"断言数"
]
[
runinfo
.
update
({
i
:
soup
.
select
(
path
(
i
))[
0
]
.
text
})
for
i
in
onlyinfolist
]
[
runinfo
.
update
({
i
:[
soup
.
select
(
path
(
i
))[
0
]
.
text
,
soup
.
select
(
path
(
i
)
+
'+div'
)[
0
]
.
text
]})
for
i
in
twoinfolist
]
for
each
in
a
.
select
(
"div[class='']>div[class='collapse']>div[class='']"
):
this
=
{
"step"
:[]}
k
=
each
.
find_all
(
'div'
,
recursive
=
False
)
this
[
"name"
]
=
k
[
0
]
.
text
.
strip
()
for
item
in
k
[
1
]
.
find_all
(
'div'
,
recursive
=
False
):
stepinfo
=
{
"断言详情"
:[]}
stepinfo
[
"name"
]
=
item
.
find
(
'h5'
)
.
text
.
strip
()
onlyinfolist
=
[
"Method"
,
"URL"
,
"耗时"
,
"返回数据"
,
"HTTP 状态码"
,
"断言通过数"
,
"断言失败数"
]
path
=
lambda
x
:
f
'div[class="card-body"]>div>div[class="row"]>div:-soup-contains("{x}")+div'
[
stepinfo
.
update
({
i
:
item
.
select
(
path
(
i
))[
0
]
.
text
})
for
i
in
onlyinfolist
]
stepinfo
[
"断言详情"
]
.
append
(
list
(
map
(
lambda
x
:
x
.
text
.
strip
(),
item
.
select
(
'div[class="card-body"]>div>div[class="row"]>div:-soup-contains("断言详情")+div>table>tbody>tr>td'
))))
this
[
"step"
]
.
append
(
stepinfo
)
runinfo
[
"运行列表"
]
.
append
(
this
)
return
jsonify
({
"code"
:
200
,
"message"
:
"请求成功"
,
"data"
:
runinfo
}),
200
int
(
project_id
)
int
(
caseid
)
except
:
return
jsonify
({
"code"
:
403
,
"message"
:
"链接格式错误"
}),
403
try
:
result
=
requests
.
get
(
f
"https://api.apifox.com/api/v1/projects/{project_id}/api-test-reports/{caseid}?locale=zh-CN"
,
headers
=
{
"authorization"
:
apifox_token
})
.
json
()
changeTime
=
lambda
x
:
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
(
float
(
x
)
/
1000
))
result
[
'data'
][
'timings'
][
"completed"
]
=
changeTime
(
result
[
'data'
][
'timings'
][
"completed"
])
result
[
'data'
][
'timings'
][
"started"
]
=
changeTime
(
result
[
'data'
][
'timings'
][
"started"
])
result
[
'url'
]
=
url
return
jsonify
({
"code"
:
200
,
"message"
:
"请求成功"
,
"data"
:
result
}),
200
except
:
return
jsonify
({
"code"
:
403
,
"message"
:
"文件内容有误,请确认"
}),
4
03
return
jsonify
({
"code"
:
503
,
"message"
:
"读取项目权限不够,请联系开发配置访问账号权限"
}),
5
03
...
...
test.py
0 → 100644
View file @
0f9cf91b
import
requests
import
time
apifox_token
=
None
def
updateapitoken
():
user
,
password
=
'wallen.ywh@galaxyoversea.com'
,
'ywh940509'
global
apifox_token
apifox_token
=
requests
.
post
(
'https://api.apifox.com/api/v1/login?locale=zh-CN'
,
json
=
{
"account"
:
user
,
"loginType"
:
"EmailPassword"
,
"password"
:
password
})
.
json
()
.
get
(
"data"
)
.
get
(
"accessToken"
)
def
a
():
url
=
'https://app.apifox.com/project/2581365/api-test/test-report/5095032'
global
apifox_token
apifox_token
or
updateapitoken
()
infolist
=
url
.
replace
(
"https://app.apifox.com/project/"
,
""
)
.
split
(
'/'
)
project_id
,
caseid
=
infolist
[
0
],
infolist
[
-
1
]
result
=
requests
.
get
(
f
"https://api.apifox.com/api/v1/projects/{project_id}/api-test-reports/{caseid}?locale=zh-CN"
,
headers
=
{
"Authorization"
:
apifox_token
})
.
json
()
changeTime
=
lambda
x
:
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
time
.
localtime
(
float
(
x
)
/
1000
))
result
[
'data'
][
'timings'
][
"completed"
]
=
changeTime
(
result
[
'data'
][
'timings'
][
"completed"
])
result
[
'data'
][
'timings'
][
"started"
]
=
changeTime
(
result
[
'data'
][
'timings'
][
"started"
])
result
[
'url'
]
=
url
return
result
q
=
' jhoiqwhe '
q
=
q
.
strip
()
print
(
q
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment