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
295502f3
Commit
295502f3
authored
May 27, 2024
by
Wallen姚文辉
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增用例上传及绑定
parent
32308a49
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
83 deletions
+103
-83
.gitignore
.gitignore
+1
-0
Tool.py
controller/Tool.py
+85
-2
mian.py
mian.py
+17
-0
test.py
test.py
+0
-81
No files found.
.gitignore
View file @
295502f3
*/__pycache__/
__pycache__/
config.yml
uploadfile/
controller/Tool.py
View file @
295502f3
...
...
@@ -6,6 +6,10 @@ import base64
import
requests
from
bs4
import
BeautifulSoup
from
manager.tools
import
sqlOrmToJson
import
xmindparser
from
copy
import
deepcopy
from
manager.tools
import
par_path
import
os
db
=
server
.
db
tool
=
Blueprint
(
"tools"
,
__name__
,
url_prefix
=
'/tool'
)
...
...
@@ -30,8 +34,6 @@ def sendport():
user
=
'wallen.ywh@galaxyoversea.com'
password
=
'Ywh940509'
yag
=
yagmail
.
SMTP
(
user
=
user
,
password
=
password
,
host
=
'smtp.exmail.qq.com'
,
port
=
465
)
print
(
data
[
"to"
])
print
(
data
[
"subject"
])
yag
.
send
(
to
=
data
[
"to"
],
cc
=
data
[
"cc"
],
subject
=
data
.
get
(
"subject"
),
contents
=
data
.
get
(
"contents"
))
return
jsonify
({
"code"
:
200
,
"message"
:
f
"{data.get('subject')}邮件发送成功"
}),
200
...
...
@@ -171,4 +173,85 @@ def editemailuser():
db
.
session
.
commit
()
db
.
session
.
close
()
return
jsonify
({
"code"
:
200
,
"message"
:
"请求成功"
}),
200
@
tool
.
route
(
'/testcase/uploadcase'
,
methods
=
[
"POST"
])
def
uplooadcase
():
data_
=
request
.
json
headers
=
getheader
(
session
.
get
(
"id"
))
result
=
requests
.
request
(
"get"
,
jiraAddress
+
"/rest/greenhopper/1.0/xboard/plan/backlog/data.json?rapidViewId="
+
str
(
data_
.
get
(
"project"
)),
headers
=
headers
)
.
json
()
projectId
,
projectkey
=
result
[
"projects"
][
0
][
"id"
],
result
[
"projects"
][
0
][
"key"
]
data
=
{
"fields"
:
{
"project"
:
{
"key"
:
projectkey
},
"summary"
:
"测试占位"
,
"description"
:
"文辉的测试"
,
"issuetype"
:
{
"name"
:
"测试用例"
},
}
}
result
=
requests
.
request
(
"post"
,
jiraAddress
+
"/rest/api/2/issue/"
,
json
=
data
,
headers
=
headers
)
.
json
()
globalcaseId
=
result
[
"id"
]
print
(
par_path
)
print
(
data_
)
file_path
=
par_path
+
'/uploadfile/'
+
data_
.
get
(
"file_name"
)
content
=
xmindparser
.
xmind_to_dict
(
file_path
)
def
a
(
suiteName
,
suiteId
,
info
,
new
,
type
):
for
each
in
info
:
oldinfo
,
newtype
=
deepcopy
(
new
),
type
if
not
((
each
[
"title"
])
==
"Map"
or
(
each
[
"title"
])
==
"测试用例"
or
(
each
[
"title"
])
==
"sheet"
or
(
each
[
"title"
])
==
"思维导图"
or
(
each
[
"title"
])
==
"逻辑图"
or
(
each
[
"title"
])
==
"括号图"
):
if
not
suiteName
:
suiteName
=
each
.
get
(
"title"
)
params
=
{
"tcIssueId"
:
globalcaseId
,
"projectId"
:
projectId
,
"sourcePage"
:
"TEST_SUITE_TEST_CASE_PAGE"
,
"decorator"
:
"dialog"
,
"inline"
:
True
}
requests
.
request
(
"post"
,
jiraAddress
+
"/secure/CreateTestSuite.jspa?projectId="
+
str
(
projectId
),
data
=
{
"inline"
:
True
,
"decorator"
:
"dialog"
,
"testSuiteName"
:
suiteName
},
headers
=
headers
)
text
=
requests
.
request
(
"get"
,
jiraAddress
+
"/secure/ShowLinkTestSuiteInPanel.jspa"
,
params
=
params
,
headers
=
headers
)
.
content
soup
=
BeautifulSoup
(
text
,
"html.parser"
)
suiteId
=
soup
.
find
(
"strong"
,
string
=
suiteName
)
.
parent
.
find
(
"input"
)
.
attrs
.
get
(
"value"
)
if
type
==
"name"
:
string
=
each
.
get
(
"title"
)
if
"tc:"
in
each
.
get
(
"title"
)
or
"tc:"
in
each
.
get
(
"title"
)
or
"tc:"
in
each
.
get
(
"title"
):
string
,
newtype
=
each
.
get
(
"title"
)
.
replace
(
"tc:"
,
""
)
.
replace
(
"tc:"
,
""
)
.
replace
(
"tc:"
,
""
),
"step"
oldinfo
[
"name"
]
=
oldinfo
.
get
(
"name"
)
and
oldinfo
.
get
(
"name"
)
+
"->"
+
string
or
string
elif
type
==
"step"
:
newtype
,
oldinfo
[
"step"
]
=
"expect"
,
each
.
get
(
"title"
)
else
:
oldinfo
[
"expect"
]
=
each
.
get
(
"title"
)
if
each
.
get
(
"topic"
)
or
each
.
get
(
"topics"
):
each
.
get
(
"topic"
)
and
a
(
suiteName
,
suiteId
,[
each
.
get
(
"topic"
)],
oldinfo
,
newtype
)
each
.
get
(
"topics"
)
and
a
(
suiteName
,
suiteId
,
each
.
get
(
"topics"
),
oldinfo
,
newtype
)
else
:
testId
=
requests
.
request
(
"post"
,
jiraAddress
+
"/rest/api/2/issue/"
,
json
=
{
"fields"
:
{
"project"
:
{
"key"
:
projectkey
},
"summary"
:
oldinfo
[
"name"
],
"issuetype"
:
{
"name"
:
"测试用例"
},
}
},
headers
=
headers
)
.
json
()[
"id"
]
requests
.
request
(
"post"
,
jiraAddress
+
"/rest/synapse/1.0/testStep/addTestStep"
,
json
=
{
"tcId"
:
testId
,
"step"
:
oldinfo
.
get
(
"step"
),
"expectedResult"
:
oldinfo
.
get
(
"expect"
),
"sequenceNumber"
:
None
},
headers
=
headers
)
requests
.
request
(
"post"
,
jiraAddress
+
"/rest/synapse/latest/testSuite/addTestCaseMemberToTestSuites"
,
json
=
{
"testSuiteIds"
:[
suiteId
],
"testCaseId"
:
testId
},
headers
=
headers
)
a
(
None
,
None
,
content
,{},
"name"
)
requests
.
request
(
"delete"
,
jiraAddress
+
"/rest/api/2/issue/"
+
globalcaseId
,
headers
=
headers
)
os
.
remove
(
file_path
)
return
jsonify
({
"code"
:
200
,
"message"
:
"用例创建成功"
}),
200
@
tool
.
route
(
'/testcase/relevancycase/<id_>'
,
methods
=
[
"POST"
])
def
relevancycase
(
id_
):
headers
=
getheader
(
session
.
get
(
"id"
))
result
=
requests
.
request
(
"get"
,
jiraAddress
+
"/rest/greenhopper/1.0/xboard/plan/backlog/data.json?rapidViewId="
+
str
(
id_
),
headers
=
headers
)
.
json
()
projectkey
=
result
[
"projects"
][
0
][
"key"
]
result
=
requests
.
request
(
"get"
,
jiraAddress
+
"/rest/greenhopper/1.0/xboard/plan/backlog/data.json?rapidViewId="
+
str
(
id_
)
+
"&selectedProjectKey="
+
projectkey
,
headers
=
headers
)
.
json
()
all
,
type_
,
storyids
=
result
.
get
(
"issues"
),{},{}
for
k
,
v
in
result
[
"entityData"
][
"types"
]
.
items
():
type_
[
str
(
k
)]
=
v
[
"typeName"
]
[
storyids
.
update
({
i
.
get
(
"key"
):[]})
for
i
in
list
(
filter
(
lambda
x
:
type_
[
x
[
"typeId"
]]
==
"Story"
,
all
))]
for
item
in
list
(
filter
(
lambda
x
:
type_
[
x
[
"typeId"
]]
==
"测试用例"
,
all
)):
for
each
in
storyids
.
keys
():
each
in
item
.
get
(
"summary"
)
and
storyids
[
each
]
.
append
(
item
.
get
(
"key"
))
for
k
,
v
in
storyids
.
items
():
requests
.
request
(
"post"
,
jiraAddress
+
"/rest/synapse/latest/requirementTestCase/addTestCase"
,
headers
=
headers
,
json
=
{
"currentReqkey"
:
k
,
"testCaseKeys"
:
v
,
"history"
:
"yes"
})
return
jsonify
({
"code"
:
200
,
"message"
:
"用例关联执行结束"
}),
200
mian.py
View file @
295502f3
import
os
import
sys
import
uuid
from
apscheduler.jobstores.sqlalchemy
import
SQLAlchemyJobStore
from
manager.serverCenter
import
server
from
manager.tools
import
par_path
class
Config
(
object
):
JOBS
=
[]
...
...
@@ -31,6 +33,21 @@ def token():
pass
else
:
return
jsonify
({
"code"
:
401
,
"message"
:
"登陆已过期"
}),
401
@
server
.
app
.
route
(
'/upload'
,
methods
=
[
"POST"
])
def
upload
():
if
'file'
not
in
request
.
files
:
return
jsonify
({
"code"
:
503
,
"message"
:
"请选择文件"
}),
503
file
=
request
.
files
[
'file'
]
l
=
file
.
filename
.
split
(
"."
)
if
file
:
if
len
(
l
)
==
2
:
file_name
=
str
(
uuid
.
uuid1
())
+
'.'
+
l
[
-
1
]
else
:
return
jsonify
({
"code"
:
503
,
"message"
:
"文件格式错误"
}),
503
# 存储文件
file
.
save
(
par_path
+
"/uploadfile/"
+
file_name
)
return
jsonify
({
"code"
:
200
,
"message"
:
"上传成功"
,
"data"
:{
"filename"
:
file_name
}}),
200
if
__name__
==
'__main__'
:
rel_path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
...
...
test.py
deleted
100644 → 0
View file @
32308a49
import
base64
import
requests
import
pandas
as
pd
import
xmindparser
from
copy
import
deepcopy
xmindparser
.
config
=
{
'showTopicId'
:
True
,
# 是否展示主题ID
'hideEmptyValue'
:
True
# 是否隐藏空值
}
def
relational_case
(
project
):
jiraAddress
,
user
,
password
=
"http://jira.galaxy-immi.com"
,
"wallen.ywh"
,
"ywh940509"
headers
=
{
"Authorization"
:
"Basic "
+
base64
.
b64encode
((
user
+
":"
+
password
)
.
encode
(
'utf-8'
))
.
decode
(),
"accept"
:
"application/json,text/javascript,*/*;q=0.01"
}
id_
=
requests
.
request
(
"get"
,
jiraAddress
+
"/rest/agile/1.0/board?projectKeyOrId="
+
project
,
headers
=
headers
)
.
json
()
.
get
(
"values"
)[
0
]
.
get
(
"id"
)
result
=
requests
.
request
(
"get"
,
jiraAddress
+
"/rest/greenhopper/1.0/xboard/plan/backlog/data.json?rapidViewId="
+
str
(
id_
)
+
"&selectedProjectKey="
+
project
,
headers
=
headers
)
.
json
()
all
=
result
.
get
(
"issues"
)
type_
=
{}
for
k
,
v
in
result
[
"entityData"
][
"types"
]
.
items
():
type_
[
str
(
k
)]
=
v
[
"typeName"
]
storyids
=
{}
[
storyids
.
update
({
i
.
get
(
"key"
):[]})
for
i
in
list
(
filter
(
lambda
x
:
type_
[
x
[
"typeId"
]]
==
"Story"
,
all
))]
for
item
in
list
(
filter
(
lambda
x
:
type_
[
x
[
"typeId"
]]
==
"测试用例"
,
all
)):
for
each
in
storyids
.
keys
():
each
in
item
.
get
(
"summary"
)
and
storyids
[
each
]
.
append
(
item
.
get
(
"key"
))
for
k
,
v
in
storyids
.
items
():
print
(
k
,
v
)
res
=
requests
.
request
(
"post"
,
jiraAddress
+
"/rest/synapse/latest/requirementTestCase/addTestCase"
,
headers
=
headers
,
json
=
{
"currentReqkey"
:
k
,
"testCaseKeys"
:
v
,
"history"
:
"yes"
})
print
(
res
.
status_code
)
print
(
res
.
url
)
print
(
res
.
headers
)
# print(res.)
def
makecase
(
filePath
):
content
=
xmindparser
.
xmind_to_dict
(
filePath
)
case_list
=
[]
# print(content)
def
a
(
info
,
new
,
type
):
for
each
in
info
:
oldinfo
=
deepcopy
(
new
)
newtype
=
type
if
not
((
each
[
"title"
])
==
"Map"
or
(
each
[
"title"
])
==
"测试用例"
or
(
each
[
"title"
])
==
"sheet"
):
if
type
==
"name"
:
string
=
each
.
get
(
"title"
)
if
"tc:"
in
each
.
get
(
"title"
)
or
"tc:"
in
each
.
get
(
"title"
)
or
"tc:"
in
each
.
get
(
"title"
):
string
=
each
.
get
(
"title"
)
.
replace
(
"tc:"
,
""
)
.
replace
(
"tc:"
,
""
)
.
replace
(
"tc:"
,
""
)
newtype
=
"step"
if
oldinfo
.
get
(
"name"
):
oldinfo
[
"name"
]
=
oldinfo
.
get
(
"name"
)
and
oldinfo
.
get
(
"name"
)
+
"->"
+
string
or
string
else
:
oldinfo
[
"name"
]
=
string
elif
type
==
"step"
:
newtype
=
"expect"
oldinfo
[
"step"
]
=
each
.
get
(
"title"
)
else
:
oldinfo
[
"expect"
]
=
each
.
get
(
"title"
)
if
each
.
get
(
"topic"
)
or
each
.
get
(
"topics"
):
(
each
.
get
(
"topic"
)
and
a
([
each
.
get
(
"topic"
)],
oldinfo
,
newtype
))
(
each
.
get
(
"topics"
)
and
a
(
each
.
get
(
"topics"
),
oldinfo
,
newtype
))
else
:
case_list
.
append
(
oldinfo
)
a
(
content
,{},
"name"
)
name
=
list
(
map
(
lambda
x
:
x
.
get
(
"name"
),
case_list
))
step
=
list
(
map
(
lambda
x
:
x
.
get
(
"step"
),
case_list
))
expect
=
list
(
map
(
lambda
x
:
x
.
get
(
"expect"
),
case_list
))
dataframe
=
pd
.
DataFrame
({
"用例名"
:
name
,
"用例步骤"
:
step
,
"预期结果"
:
expect
})
dataframe
.
to_csv
(
"test.csv"
,
index
=
False
,
sep
=
','
)
# makecase("/home/yaowenhui/galaxTestCenter/1.07.xmind")
# relational_case("STARCOM")
a
=
1
b
=
a
and
12
or
13
print
(
b
)
\ 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