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
c553d9fb
Commit
c553d9fb
authored
May 31, 2024
by
Wallen姚文辉
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
外部调用的用例上传及关联
parent
cd8f79da
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
437 additions
and
12 deletions
+437
-12
Tool.py
controller/Tool.py
+253
-8
notoken.py
controller/notoken.py
+133
-0
socketevent.py
controller/socketevent.py
+25
-0
serverCenter.py
manager/serverCenter.py
+3
-0
mian.py
mian.py
+7
-3
Model.py
model/Model.py
+16
-1
No files found.
controller/Tool.py
View file @
c553d9fb
from
flask
import
Blueprint
,
request
,
jsonify
,
session
import
time
import
uuid
from
flask
import
Blueprint
,
request
,
jsonify
,
session
,
current_app
from
manager.serverCenter
import
server
from
manager.serverCenter
import
server
from
model.Model
import
User
,
Emails
from
model.Model
import
User
,
Emails
,
Uploadecase
import
base64
import
base64
import
requests
import
requests
from
bs4
import
BeautifulSoup
from
bs4
import
BeautifulSoup
...
@@ -10,6 +12,8 @@ import xmindparser
...
@@ -10,6 +12,8 @@ import xmindparser
from
copy
import
deepcopy
from
copy
import
deepcopy
from
manager.tools
import
par_path
from
manager.tools
import
par_path
import
os
import
os
from
threading
import
Thread
from
flask_socketio
import
emit
,
send
db
=
server
.
db
db
=
server
.
db
tool
=
Blueprint
(
"tools"
,
__name__
,
url_prefix
=
'/tool'
)
tool
=
Blueprint
(
"tools"
,
__name__
,
url_prefix
=
'/tool'
)
...
@@ -255,10 +259,113 @@ def uplooadcase():
...
@@ -255,10 +259,113 @@ def uplooadcase():
os
.
remove
(
file_path
)
os
.
remove
(
file_path
)
return
jsonify
({
"code"
:
200
,
"message"
:
"用例创建成功"
}),
200
return
jsonify
({
"code"
:
200
,
"message"
:
"用例创建成功"
}),
200
@
tool
.
route
(
'/testcase/relevancycase/<id_>'
,
methods
=
[
"POST"
])
def
relevancycase
(
id_
):
@
tool
.
route
(
'/testcase/uploadhistory'
,
methods
=
[
"GET"
])
headers
=
getheader
(
session
.
get
(
"id"
))
def
uploadhistory
():
id_
=
requests
.
request
(
"get"
,
jiraAddress
+
"/rest/agile/1.0/board?projectKeyOrId="
+
id_
,
headers
=
headers
)
.
json
()
.
get
(
"values"
)[
0
]
.
get
(
"id"
)
data
=
request
.
args
page_size
=
int
(
data
.
get
(
"page_size"
))
page_num
=
int
(
data
.
get
(
"page_num"
))
result
=
db
.
session
.
query
(
Uploadecase
.
id
,
Uploadecase
.
filename
,
Uploadecase
.
project
,
Uploadecase
.
step
,
Uploadecase
.
stepstatus
,
Uploadecase
.
status
,
Uploadecase
.
create_time
,
Uploadecase
.
case_count
)
.
filter_by
(
user_id
=
session
.
get
(
"id"
))
.
order_by
(
Uploadecase
.
create_time
.
desc
())
.
paginate
(
page
=
page_num
,
per_page
=
page_size
)
total_sum
=
result
.
total
res
=
result
.
items
db
.
session
.
close
()
return
jsonify
({
"code"
:
200
,
"message"
:
"请求成功"
,
"data"
:{
"rows"
:
sqlOrmToJson
(
res
),
"total"
:
total_sum
}}),
200
@
tool
.
route
(
'/testcase/upload'
,
methods
=
[
"POST"
])
def
run
():
a
=
Uploadecase
(
project
=
request
.
form
.
get
(
"projectName"
),
user_id
=
session
.
get
(
"id"
),
step
=
0
,
stepstatus
=
0
,
status
=
0
,
create_time
=
time
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
,
time
.
localtime
(
time
.
time
())))
if
'file'
not
in
request
.
files
:
a
.
stepstatus
=
1
a
.
status
=
1
db
.
session
.
add
(
a
)
db
.
session
.
commit
()
db
.
session
.
close
()
return
jsonify
({
"code"
:
503
,
"message"
:
"请选择文件"
}),
503
file
=
request
.
files
[
'file'
]
if
file
.
filename
.
split
(
"."
)[
-
1
]
!=
"xmind"
:
a
.
stepstatus
=
1
a
.
status
=
1
db
.
session
.
add
(
a
)
db
.
session
.
commit
()
db
.
session
.
close
()
return
jsonify
({
"code"
:
503
,
"message"
:
"文件格式错误"
}),
503
a
.
filename
=
file
.
filename
file_name
=
str
(
uuid
.
uuid1
())
+
'.'
+
file
.
filename
.
split
(
"."
)[
-
1
]
file
.
save
(
par_path
+
"/uploadfile/"
+
file_name
)
db
.
session
.
add
(
a
)
db
.
session
.
flush
()
upid
=
a
.
id
db
.
session
.
commit
()
db
.
session
.
close
()
# h=Thread(target=runstart,args=(current_app._get_current_object(),file_name,request.form.get("project"),upid,session.get("id")))
# h.start()
# server.socketio.start_background_task(runstart,current_app._get_current_object(),file_name,request.form.get("project"),upid,session.get("id"))
# server.socketio.emit("www",room=)
from
controller.socketevent
import
target
print
(
target
)
emit
(
"www"
,
to
=
target
,
namespace
=
'/'
)
return
jsonify
({
"code"
:
200
,
"message"
:
"上传成功"
}),
200
def
runstart
(
app
,
file_name
,
project
,
upid
,
user_id
):
with
app
.
app_context
():
headers
=
getheader
(
user_id
)
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_
),
headers
=
headers
)
.
json
()
projectId
,
projectkey
=
result
[
"projects"
][
0
][
"id"
],
result
[
"projects"
][
0
][
"key"
]
data
=
{
"fields"
:
{
"project"
:
{
"key"
:
projectkey
},
"summary"
:
"测试占位"
,
"description"
:
"文辉的测试"
,
"issuetype"
:
{
"name"
:
"测试用例"
},
}
}
case_count
=
[
0
]
result
=
requests
.
request
(
"post"
,
jiraAddress
+
"/rest/api/2/issue/"
,
json
=
data
,
headers
=
headers
)
.
json
()
globalcaseId
=
result
[
"id"
]
def
up
(
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"
])
==
"括号图"
or
"画布"
in
(
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
up
(
suiteName
,
suiteId
,[
each
.
get
(
"topic"
)],
oldinfo
,
newtype
)
each
.
get
(
"topics"
)
and
up
(
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
)
case_count
[
0
]
=+
case_count
[
0
]
def
relevancycase
(
pro
):
id_
=
requests
.
request
(
"get"
,
jiraAddress
+
"/rest/agile/1.0/board?projectKeyOrId="
+
pro
,
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_
),
headers
=
headers
)
.
json
()
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"
]
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
()
result
=
requests
.
request
(
"get"
,
jiraAddress
+
"/rest/greenhopper/1.0/xboard/plan/backlog/data.json?rapidViewId="
+
str
(
id_
)
+
"&selectedProjectKey="
+
projectkey
,
headers
=
headers
)
.
json
()
...
@@ -273,3 +380,141 @@ def relevancycase(id_):
...
@@ -273,3 +380,141 @@ def relevancycase(id_):
requests
.
request
(
"post"
,
jiraAddress
+
"/rest/synapse/latest/requirementTestCase/addTestCase"
,
headers
=
headers
,
json
=
{
"currentReqkey"
:
k
,
"testCaseKeys"
:
v
,
"history"
:
"yes"
})
requests
.
request
(
"post"
,
jiraAddress
+
"/rest/synapse/latest/requirementTestCase/addTestCase"
,
headers
=
headers
,
json
=
{
"currentReqkey"
:
k
,
"testCaseKeys"
:
v
,
"history"
:
"yes"
})
return
jsonify
({
"code"
:
200
,
"message"
:
"用例关联执行结束"
}),
200
return
jsonify
({
"code"
:
200
,
"message"
:
"用例关联执行结束"
}),
200
a
=
db
.
session
.
query
(
Uploadecase
)
.
filter_by
(
id
=
upid
)
.
first
()
a
.
step
=
1
a
.
stepstatus
=
0
db
.
session
.
commit
()
server
.
socketio
.
emit
(
"infoupdate"
,
room
=
a
.
id
)
content
=
xmindparser
.
xmind_to_dict
(
par_path
+
"/uploadfile/"
+
file_name
)
# try:
up
(
None
,
None
,
content
,{},
"name"
)
requests
.
request
(
"delete"
,
jiraAddress
+
"/rest/api/2/issue/"
+
globalcaseId
,
headers
=
headers
)
a
.
step
=
2
a
.
stepstatus
=
0
a
.
case_count
=
case_count
[
0
]
db
.
session
.
commit
()
server
.
socketio
.
send
(
"infoupdate"
,
room
=
a
.
id
)
# except:
# a.stepstatus=1
# a.status=1
# a.case_count=case_count
# db.session.commit()
# server.socketio.emit("infoupdate",room=a.id)
# db.session.close()
# return
try
:
relevancycase
(
project
)
a
.
step
=
3
a
.
stepstatus
=
2
a
.
status
=
1
db
.
session
.
commit
()
server
.
socketio
.
send
(
"infoupdate"
,
room
=
a
.
id
)
except
:
a
.
stepstatus
=
1
a
.
status
=
1
db
.
session
.
commit
()
server
.
socketio
.
send
(
"infoupdate"
,
room
=
a
.
id
)
db
.
session
.
close
()
import
os
import
requests
from
urllib.parse
import
urlparse
def
download_file
(
url
):
response
=
requests
.
get
(
url
,
stream
=
True
)
response
.
raise_for_status
()
download_dir
=
'./upload'
os
.
makedirs
(
download_dir
,
exist_ok
=
True
)
file_name
=
os
.
path
.
basename
(
urlparse
(
url
)
.
path
)
file_path
=
os
.
path
.
join
(
download_dir
,
file_name
)
with
open
(
file_path
,
'wb'
)
as
file
:
for
chunk
in
response
.
iter_content
(
chunk_size
=
8192
):
if
chunk
:
file
.
write
(
chunk
)
return
file_path
def
uploadcase
(
project
,
file_path
,
headers
):
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_
),
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"
]
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"
])
==
"括号图"
or
"画布"
in
(
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
)
def
relevancycase
(
project
,
headers
):
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_
),
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"
})
def
run
(
url
,
project
):
headers
=
{
"Authorization"
:
"Basic "
+
base64
.
b64encode
((
"username:password"
)
.
encode
(
'utf-8'
))
.
decode
(),
"accept"
:
"application/json,text/javascript,*/*;q=0.01"
}
file_path
=
download_file
(
url
)
\ No newline at end of file
controller/notoken.py
0 → 100644
View file @
c553d9fb
import
os
import
requests
from
urllib.parse
import
urlparse
from
copy
import
deepcopy
import
xmindparser
import
base64
import
requests
from
bs4
import
BeautifulSoup
from
flask
import
Blueprint
,
request
,
jsonify
from
threading
import
Thread
jiraAddress
=
"http://jira.galaxy-immi.com"
notoken
=
Blueprint
(
"notoken"
,
__name__
,
url_prefix
=
'/notoken'
)
runinfo
=
{}
def
download_file
(
id
,
url
):
global
runinfo
runinfo
[
id
]
=
0
response
=
requests
.
get
(
url
,
stream
=
True
)
response
.
raise_for_status
()
download_dir
=
'./upload'
os
.
makedirs
(
download_dir
,
exist_ok
=
True
)
file_name
=
os
.
path
.
basename
(
urlparse
(
url
)
.
path
)
file_path
=
os
.
path
.
join
(
download_dir
,
file_name
)
with
open
(
file_path
,
'wb'
)
as
file
:
for
chunk
in
response
.
iter_content
(
chunk_size
=
8192
):
if
chunk
:
file
.
write
(
chunk
)
return
file_path
def
uploadcase
(
id
,
project
,
file_path
,
headers
):
global
runinfo
runinfo
[
id
]
=
1
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_
),
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"
]
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"
])
==
"括号图"
or
"画布"
in
(
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
)
def
relevancycase
(
id
,
project
,
headers
):
global
runinfo
runinfo
[
id
]
=
2
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_
),
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"
})
def
run
(
id
,
url
,
project
):
headers
=
{
"Authorization"
:
"Basic "
+
base64
.
b64encode
((
"betty.zww:AAAaaa111"
)
.
encode
(
'utf-8'
))
.
decode
(),
"accept"
:
"application/json,text/javascript,*/*;q=0.01"
}
file_path
=
download_file
(
id
,
url
)
uploadcase
(
id
,
project
,
file_path
,
headers
)
relevancycase
(
id
,
project
,
headers
)
global
runinfo
del
runinfo
[
id
]
@
notoken
.
route
(
'/uploadcase'
,
methods
=
[
"POST"
])
def
uploadcase
():
thr
=
Thread
(
target
=
run
,
args
=
(
request
.
json
.
get
(
"id"
),
request
.
json
.
get
(
"url"
),
request
.
json
.
get
(
"project"
)))
thr
.
start
()
return
jsonify
({
"code"
:
200
,
"message"
:
"请求成功"
}),
200
@
notoken
.
route
(
'/upstatus/<id_>'
,
methods
=
[
"GET"
])
def
upstatus
(
id_
):
global
runinfo
return
jsonify
({
"code"
:
200
,
"message"
:
"请求成功"
,
"status"
:
runinfo
.
get
(
id_
)}),
200
\ No newline at end of file
controller/socketevent.py
0 → 100644
View file @
c553d9fb
from
manager.serverCenter
import
server
from
flask_socketio
import
join_room
,
leave_room
from
flask
import
request
target
=
None
@
server
.
socketio
.
on
(
"connect"
)
def
on_connect
():
global
target
target
=
request
.
sid
@
server
.
socketio
.
on
(
'join'
)
def
on_join
(
data
):
print
(
"我加入了房间"
)
print
(
data
)
join_room
(
data
)
@
server
.
socketio
.
on
(
'leave'
)
def
on_leave
(
data
):
print
(
"我离开了房间"
)
print
(
data
)
leave_room
(
data
)
manager/serverCenter.py
View file @
c553d9fb
from
flask
import
Flask
from
flask
import
Flask
import
os
import
os
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_socketio
import
SocketIO
,
emit
,
join_room
,
leave_room
,
close_room
from
datetime
import
timedelta
from
datetime
import
timedelta
from
manager.tools
import
get_config
from
manager.tools
import
get_config
...
@@ -16,6 +17,8 @@ class server():
...
@@ -16,6 +17,8 @@ class server():
app
.
config
[
'PERMANENT_SESSION_LIFETIME'
]
=
timedelta
(
days
=
7
)
app
.
config
[
'PERMANENT_SESSION_LIFETIME'
]
=
timedelta
(
days
=
7
)
app
.
secret_key
=
"test"
app
.
secret_key
=
"test"
db
=
SQLAlchemy
(
app
)
db
=
SQLAlchemy
(
app
)
socketio
=
SocketIO
()
socketio
.
init_app
(
app
,
cors_allowed_origins
=
'*'
)
...
...
mian.py
View file @
c553d9fb
...
@@ -3,6 +3,7 @@ import sys
...
@@ -3,6 +3,7 @@ import sys
import
uuid
import
uuid
from
apscheduler.jobstores.sqlalchemy
import
SQLAlchemyJobStore
from
apscheduler.jobstores.sqlalchemy
import
SQLAlchemyJobStore
from
manager.serverCenter
import
server
from
manager.serverCenter
import
server
from
controller.socketevent
import
*
from
manager.tools
import
par_path
from
manager.tools
import
par_path
class
Config
(
object
):
class
Config
(
object
):
...
@@ -16,7 +17,7 @@ class Config(object):
...
@@ -16,7 +17,7 @@ class Config(object):
@
server
.
app
.
before_request
@
server
.
app
.
before_request
def
token
():
def
token
():
token
=
request
.
headers
.
get
(
"token"
)
token
=
request
.
headers
.
get
(
"token"
)
release_path
=
[
"/user/login"
,
"/user/logout"
]
release_path
=
[
"/user/login"
,
"/user/logout"
,
'notoken'
]
next_
=
False
next_
=
False
for
i
in
release_path
:
for
i
in
release_path
:
if
i
in
request
.
path
:
if
i
in
request
.
path
:
...
@@ -57,7 +58,6 @@ def upload():
...
@@ -57,7 +58,6 @@ def upload():
file
.
save
(
par_path
+
"/uploadfile/"
+
file_name
)
file
.
save
(
par_path
+
"/uploadfile/"
+
file_name
)
return
jsonify
({
"code"
:
200
,
"message"
:
"上传成功"
,
"data"
:{
"filename"
:
file_name
}}),
200
return
jsonify
({
"code"
:
200
,
"message"
:
"上传成功"
,
"data"
:{
"filename"
:
file_name
}}),
200
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
rel_path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
rel_path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
rel_path
not
in
sys
.
path
:
if
rel_path
not
in
sys
.
path
:
...
@@ -73,7 +73,11 @@ if __name__ == '__main__':
...
@@ -73,7 +73,11 @@ if __name__ == '__main__':
from
controller.Tool
import
*
from
controller.Tool
import
*
server
.
app
.
register_blueprint
(
tool
)
server
.
app
.
register_blueprint
(
tool
)
server
.
app
.
run
(
host
=
"0.0.0.0"
,
port
=
8000
,
debug
=
True
)
from
controller.notoken
import
*
server
.
app
.
register_blueprint
(
notoken
)
# server.app.run(host="0.0.0.0", port=8000, debug=True)
server
.
socketio
.
run
(
server
.
app
,
host
=
"0.0.0.0"
,
port
=
8000
,
debug
=
True
)
...
...
model/Model.py
View file @
c553d9fb
...
@@ -99,6 +99,21 @@ class Emails(db.Model):
...
@@ -99,6 +99,21 @@ class Emails(db.Model):
default_cc
=
Column
(
Integer
,
nullable
=
False
,
server_default
=
text
(
"0"
),
comment
=
'默认抄送人,1true-0false'
)
default_cc
=
Column
(
Integer
,
nullable
=
False
,
server_default
=
text
(
"0"
),
comment
=
'默认抄送人,1true-0false'
)
address
=
Column
(
String
(
64
),
nullable
=
False
,
comment
=
'地址'
)
address
=
Column
(
String
(
64
),
nullable
=
False
,
comment
=
'地址'
)
class
Uploadecase
(
db
.
Model
):
'''
上传用例信息记录表
'''
__tablename__
=
"uploadcase"
__table_args__
=
{
'mysql_engine'
:
'InnoDB'
,
'mysql_charset'
:
'utf8mb4'
}
id
=
Column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
filename
=
Column
(
String
(
64
),
nullable
=
True
,
comment
=
'上传的文件名'
)
project
=
Column
(
String
(
64
),
nullable
=
False
,
comment
=
'项目名'
)
user_id
=
Column
(
Integer
,
nullable
=
False
,
comment
=
'上传用例的人员id'
)
step
=
Column
(
Integer
,
nullable
=
False
,
server_default
=
text
(
"0"
),
comment
=
'当前阶段 0-上传文件 1-插入用例 2-关联用例'
)
stepstatus
=
Column
(
Integer
,
nullable
=
False
,
comment
=
'当前步骤的状态 0运行中,1错误,2结束'
)
status
=
Column
(
Integer
,
nullable
=
False
,
comment
=
'状态 0-执行中 1-已结束'
)
case_count
=
Column
(
Integer
,
nullable
=
False
,
server_default
=
text
(
"0"
),
comment
=
'状态 0-执行中 1-已结束'
)
create_time
=
Column
(
DateTime
,
nullable
=
False
,
comment
=
"创建时间"
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
with
server
.
app
.
app_context
():
with
server
.
app
.
app_context
():
...
...
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