Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
willdesk_apiauto
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
29
Issues
29
List
Boards
Labels
Service Desk
Milestones
Merge Requests
29
Merge Requests
29
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
桦生 詹
willdesk_apiauto
Commits
3d7f72c3
"YamlCase/git@172.16.40.31:zhanhuasheng/willdesk_apiauto.git" did not exist on "3e90e5a00f709be3bcb33cd77652c0e70cc37ac0"
Commit
3d7f72c3
authored
Mar 08, 2024
by
zhanhuasheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
兼容websocket消息收发断言
parent
21fc9e89
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
44 deletions
+56
-44
Utils/req_handler.py
Utils/req_handler.py
+31
-23
Utils/websocket_handler.py
Utils/websocket_handler.py
+25
-21
No files found.
Utils/req_handler.py
View file @
3d7f72c3
...
...
@@ -114,6 +114,7 @@ class ReqHandler:
:param expected: 传入期望结果
:return:
'''
try
:
assert
res
.
status_code
==
200
#先断言状态码是正确的
if
isinstance
(
expected
,
list
):
'''
...
...
@@ -125,8 +126,12 @@ class ReqHandler:
path
=
list
(
item_value
.
keys
())[
0
]
#拿到path路径
value
=
list
(
item_value
.
values
())[
0
]
res_path_value
=
jsonpath
.
jsonpath
(
res
.
json
(),
path
)[
0
]
if
isinstance
(
res_path_value
,
str
)
and
'{"contentList":'
in
res_path_value
:
res_path_value
=
res_path_value
.
replace
(
'
\\
'
,
''
)
if
assert_way
==
'eq'
:
#eq代表完全相同
assert
value
==
res_path_value
elif
assert_way
==
'like'
:
#代表值相同但是type可能不同
assert
str
(
value
)
==
str
(
res_path_value
)
elif
assert_way
==
'not_eq'
:
#not_eq代表不相同
assert
value
!=
res_path_value
elif
assert_way
==
'almost'
:
#almonst代表四舍五入后相同就判断为一致
...
...
@@ -135,8 +140,11 @@ class ReqHandler:
assert
value
in
res_path_value
elif
assert_way
==
'ain'
:
assert
res_path_value
in
value
except
AssertionError
:
print
(
f
'期望值为
{
value
}
(
{
type
(
value
)
}
),实际返回值为
{
res_path_value
}
(
{
type
(
res_path_value
)
}
),完整的expected体为
{
expected
}
'
)
raise
AssertionError
except
Exception
as
e
:
print
(
e
,
'-----------------'
)
def
set_value_handler
(
self
,
res
,
item
,
var_class
):
'''
:param res: 传response请求体
...
...
Utils/websocket_handler.py
View file @
3d7f72c3
...
...
@@ -39,9 +39,9 @@ class ws:
async
def
send_message
(
self
,
message
):
if
self
.
websocket
and
self
.
websocket
.
open
:
try
:
print
(
'开始发送消息'
)
await
self
.
websocket
.
send
(
message
)
print
(
f
"Sent message:
{
message
}
"
)
time
.
sleep
(
0.5
)
except
websockets
.
ConnectionClosed
as
e
:
await
self
.
close
()
except
Exception
:
...
...
@@ -95,10 +95,8 @@ async def ws_action(ws,case):
async
def
ws_send_handler
(
case
,
ws
):
data
=
case
[
'data'
]
# 消息数据
if
data
[
'type'
]
in
[
'text'
,
'emoji'
]:
content
=
r
'{"contentList":"%s","attachmentList":[]}'
%
data
[
'content'
]
else
:
content
=
getattr
(
livechatData
,
data
[
'type'
])
content
=
getattr
(
livechatData
,
data
[
'type'
])
#根据type取到对应格式的content
if
data
[
'type'
]
!=
'rate'
:
msgType
=
'newstext'
else
:
...
...
@@ -161,6 +159,7 @@ def ws_assert(expected,msg):
:param res: 返回的信息
:return:
'''
try
:
for
item
in
expected
:
# 循环每一个断言场景
for
item_key
,
item_value
in
item
.
items
():
assert_way
=
item_key
...
...
@@ -171,12 +170,17 @@ def ws_assert(expected,msg):
assert
value
==
res_path_value
elif
assert_way
==
'not_eq'
:
# not_eq代表不相同
assert
value
!=
res_path_value
elif
assert_way
==
'like'
:
# 代表值相同但是type可能不同
assert
str
(
value
)
==
str
(
res_path_value
)
elif
assert_way
==
'almost'
:
# almonst代表四舍五入后相同就判断为一致
assert
round
(
value
,
2
)
==
round
(
res_path_value
,
2
)
elif
assert_way
==
'in'
:
# in代表断言值在返回值中
assert
value
in
res_path_value
elif
assert_way
==
'ain'
:
assert
res_path_value
in
value
except
AssertionError
:
print
(
f
'期望值为
{
value
}
(
{
type
(
value
)
}
),实际返回值为
{
res_path_value
}
(
{
type
(
res_path_value
)
}
),完整的expected体为
{
expected
}
'
)
raise
AssertionError
async
def
ws_run
(
ws
,
case
):
...
...
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