Commit c8af987e authored by zhanhuasheng's avatar zhanhuasheng

兼容websockets

parent 16159520
...@@ -9,6 +9,5 @@ class TestAccount: ...@@ -9,6 +9,5 @@ class TestAccount:
yaml_data = yaml_handler.yaml_handler.get_case(yaml_path) yaml_data = yaml_handler.yaml_handler.get_case(yaml_path)
@pytest.mark.parametrize('case',yaml_data) @pytest.mark.parametrize('case',yaml_data)
def test_account(self,case): def test_account(self,case):
# case = req_handler.ReqHandler.params_handler(case=case,var_class=accountData) #替换变量
req_handler.ReqHandler.send_requests(case=case,var_class=accountData) req_handler.ReqHandler.send_requests(case=case,var_class=accountData)
print(case) print(case)
\ No newline at end of file
...@@ -9,6 +9,5 @@ class TestBuyPlan: ...@@ -9,6 +9,5 @@ class TestBuyPlan:
yaml_data = yaml_handler.yaml_handler.get_case(yaml_path) yaml_data = yaml_handler.yaml_handler.get_case(yaml_path)
@pytest.mark.parametrize('case',yaml_data) @pytest.mark.parametrize('case',yaml_data)
def test_buy_plan(self,case): def test_buy_plan(self,case):
case = req_handler.ReqHandler.params_handler(case=case,var_class=buyPlanData) #替换变量
req_handler.ReqHandler.send_requests(case=case,var_class=buyPlanData) req_handler.ReqHandler.send_requests(case=case,var_class=buyPlanData)
print(case) print(case)
\ No newline at end of file
...@@ -60,7 +60,7 @@ class ReqHandler: ...@@ -60,7 +60,7 @@ class ReqHandler:
encoding='utf8') as f: encoding='utf8') as f:
content = f.read() content = f.read()
exec(content) exec(content)
return return 1
url = case['url'] if 'http' in case['url'] else config_handler.base_config.get_value('url','test_address') + case['url'] #判断是否有域名,没有的话给config文件中的默认测试域名 url = case['url'] if 'http' in case['url'] else config_handler.base_config.get_value('url','test_address') + case['url'] #判断是否有域名,没有的话给config文件中的默认测试域名
method = case['method'] method = case['method']
expected = case['expected'] expected = case['expected']
...@@ -72,7 +72,6 @@ class ReqHandler: ...@@ -72,7 +72,6 @@ class ReqHandler:
if case.get('headers'): if case.get('headers'):
for key,value in case['headers'].items(): for key,value in case['headers'].items():
headers[key] = value headers[key] = value
if method == 'post': if method == 'post':
if headers.get('content-type') == 'application/x-www-form-urlencoded' or headers.get('content-type') == 'text/xml': if headers.get('content-type') == 'application/x-www-form-urlencoded' or headers.get('content-type') == 'text/xml':
res = requests.request(url=url,method=method,data=data,headers=headers) res = requests.request(url=url,method=method,data=data,headers=headers)
...@@ -84,31 +83,6 @@ class ReqHandler: ...@@ -84,31 +83,6 @@ class ReqHandler:
res = requests.request(url=url,method=method,data=data,headers=headers) res = requests.request(url=url,method=method,data=data,headers=headers)
self.assert_handler(self,res=res,expected=expected) self.assert_handler(self,res=res,expected=expected)
if case.get('set_value'): if case.get('set_value'):
import random
async def test_recv():
data = json.dumps({
'action': "sendmsg",
'data': {
'avatar': "https://img.willdesk.com/${picUrl}",
'clientId': websocket_handler.ws_willdesk.client_id,
'fromId': '35948', #c端userId
'isNote': False,
'message': '{\"contentList\":\"testtesttest<br>\",\"attachmentList\":[]}',
'msgType': 'newstext',
'platform': 1,
'roomChannelType': 'wk',
'roomId': '502856393624136484',
'roomPlatform': 'willdesk',
'siteId': '7238', #店铺id
'uType': 2,
'uid': '5746', #userId
'username': 'zhs' #品牌名称
},
'seq': str(random.randint(1000000000000000, 9999999999999999))
})
await websocket_handler.ws_willdesk.send_message(data)
# await websocket_handler.ws_willdesk.receive_message()
asyncio.run(test_recv())
self.set_value_handler(self,res=res,item=case['set_value'],var_class=var_class) self.set_value_handler(self,res=res,item=case['set_value'],var_class=var_class)
if case.get('after_sql'): if case.get('after_sql'):
sql = case['after_sql'] sql = case['after_sql']
...@@ -129,8 +103,9 @@ class ReqHandler: ...@@ -129,8 +103,9 @@ class ReqHandler:
ws = case['ws'] # 操作端 ws = case['ws'] # 操作端
if ws not in ['willdesk', 'customer']: if ws not in ['willdesk', 'customer']:
raise Exception('websocket操作端填写有误') raise Exception('websocket操作端填写有误')
websocket = websocket_handler.ws_willdesk if ws == 'willdesk' else websocket_handler.ws_customer websocket = websocket_handler.ws_willdesk if ws == 'willdesk' else websocket_handler.ws_client
websocket_handler.ws_run(ws=websocket,case=case) # websocket_handler.ws_run(ws=websocket,case=case)
websocket_handler.loop.run_until_complete(websocket_handler.ws_run(ws=websocket, case=case))
def assert_handler(self,res,expected): def assert_handler(self,res,expected):
''' '''
......
...@@ -2,6 +2,10 @@ import asyncio ...@@ -2,6 +2,10 @@ import asyncio
import websockets import websockets
import time,random,json,jsonpath import time,random,json,jsonpath
from Utils.global_variate import Global from Utils.global_variate import Global
from TestData.inbox.livechat_test_data import livechatData
loop = asyncio.get_event_loop() #异步主线
class ws: class ws:
def __init__(self, url, attr): def __init__(self, url, attr):
...@@ -9,20 +13,25 @@ class ws: ...@@ -9,20 +13,25 @@ class ws:
self.websocket = None self.websocket = None
self.loop = asyncio.get_event_loop() self.loop = asyncio.get_event_loop()
self.client_id = '' self.client_id = ''
self.attr = attr
async def connect(self): async def get_client_id(self):
try: if not self.websocket:
self.websocket = await websockets.connect(self.url) self.websocket = await websockets.connect(self.url)
enter_res = eval(await self.websocket.recv()) enter_res = json.loads(await self.websocket.recv())
if enter_res.get('action'): if enter_res.get('action'):
if enter_res['action'] in ['readMsg','tipmsg']: if enter_res['action'] in ['readMsg', 'tipmsg']:
self.client_id = enter_res['data']['clientId'] self.client_id = enter_res['data']['clientId']
elif enter_res['action'] =='sendmsg': elif enter_res['action'] == 'sendmsg':
self.client_id = enter_res['data']['response']['clientId'] self.client_id = enter_res['data']['response']['clientId']
else: #action是heartbeat的情况 else: # action是heartbeat的情况
self.client_id = enter_res['data']['cliend'] self.client_id = enter_res['data']['cliend']
else: #action是enter的情况 else: # action是enter的情况
self.client_id = enter_res['data']['clientId'] self.client_id = enter_res['data']['clientId']
async def connect(self):
try:
self.websocket = await websockets.connect(self.url)
await self.get_client_id()
# print(f"Connected to {self.url}") # print(f"Connected to {self.url}")
except websockets.ConnectionClosed as e: except websockets.ConnectionClosed as e:
await self.close() await self.close()
...@@ -37,9 +46,8 @@ class ws: ...@@ -37,9 +46,8 @@ class ws:
await self.close() await self.close()
except Exception: except Exception:
print('error') print('error')
else: else:
# print('send重新链接') print('send重新链接')
await self.connect() await self.connect()
await self.send_message(message) await self.send_message(message)
...@@ -54,14 +62,13 @@ class ws: ...@@ -54,14 +62,13 @@ class ws:
await self.close() await self.close()
except NameError: except NameError:
return message return message
except Exception as e:
print(e)
else: else:
print('receive重新链接') print('receive重新链接')
await self.connect() await self.connect()
return await self.receive_message() return await self.receive_message()
def ws_sendmsg(self,case):
pass
async def close(self): async def close(self):
if self.websocket: if self.websocket:
await self.websocket.close() await self.websocket.close()
...@@ -74,42 +81,36 @@ async def ws_action(ws,case): ...@@ -74,42 +81,36 @@ async def ws_action(ws,case):
:param case: 传入用例数据 :param case: 传入用例数据
''' '''
action = case['action'] #操作 action = case['action'] #操作
expected = case['expected'] #断言
if action == 'sendmsg': if action == 'sendmsg':
response = ws_send_handler(case=case,ws=ws) response = await ws_send_handler(case=case,ws=ws)
assert response['response']['code'] == 200 assert response['response']['code'] == 200
assert response['action'] == 'sendmsg' assert response['action'] == 'sendmsg'
elif action == 'receive': elif action == 'receive':
expected = case['expected'] # 断言
if ws.client_id == '':
await ws.get_client_id()
msg = json.loads(await ws.receive_message())
ws_assert(expected=expected,msg=msg)
msg = await ws.receive_message() async def ws_send_handler(case,ws):
while msg['action'] == 'heartbeat':
time.sleep(0.1)
msg = await ws.receive_message()
result = ws_assert(expected=expected,msg=msg)
assert result
def ws_send_handler(case,ws):
if case.get('file'):
'''预留文件处理区'''
data = case['data'] # 消息数据 data = case['data'] # 消息数据
msgType = 'newstext' msgType = 'newstext'
if data['type'] in ['text', 'emoji']: if data['type'] in ['text', 'emoji']:
content = r'{"contentList":"%s","attachmentList":[]}' % data['content'] content = r'{"contentList":"%s","attachmentList":[]}' % data['content']
elif data['type'] == 'picture': elif data['type'] == 'image':
content = r'{"contentList":"<div data-type="willdesk-image" class="willdesk-chat-image" contenteditable="false"><img src="https://img.willdesk.com/test/chat/5973/2024/03/06/078ee3ce18c91ab608c4949705d1cfef/png图片_1024×1024.png" data-width="1024" data-height="1024" data-size="219148" data-chattagtype="wd-img" style="max-height: 200px; max-width: 200px; vertical-align: bottom; margin: 2px 0px; border-radius: 4px; width: 200px; height: 200px;"></div> <br>","attachmentList":[]}' content = "{\"contentList\":\"<div data-type=\\\"willdesk-image\\\" class=\\\"willdesk-chat-image\\\" contenteditable=\\\"false\\\"><img src=\\\"%s\\\" data-width=\\\"64\\\" data-height=\\\"64\\\" data-size=\\\"1268\\\" data-chattagtype=\\\"wd-img\\\" style=\\\"max-height: 200px; max-width: 200px; vertical-align: bottom; margin: 2px 0px; border-radius: 4px; width: 64px; height: 64px;\\\"></div> <br>\",\"attachmentList\":[]}"%livechatData.imgSrc
elif data['type'] == 'file': elif data['type'] == 'file':
content = r'{"contentList":"","attachmentList":[{"src":"https://img.willdesk.com/test/chat/5973/2024/03/06/6e7d5240ef4f8ecec7430851f764b2ee/新建_文本文档.txt","blobSrc":"https://img.willdesk.com/test/chat/5973/2024/03/06/6e7d5240ef4f8ecec7430851f764b2ee/新建_文本文档.txt","name":"新建 文本文档.txt","size":0,"type":"text/plain"}]}' content = r'{"contentList":"","attachmentList":[{"src":"%s","blobSrc":"%s","name":"新建 文本文档.txt","size":0,"type":"text/plain"}]}'%(livechatData.fileSrc,livechatData.fileSrc)
elif data['type'] == 'article': elif data['type'] == 'article':
content = r'{"contentList":"<div data-type="willdesk-faq" style="background: rgb(255, 255, 255); border-radius: 8px; min-width: 230px; max-width: 100%; width: 300px; box-sizing: border-box; position: relative; border: 0.5px solid rgb(229, 229, 235);"><div style="padding: 12px 16px 0px; color: rgb(18, 17, 39); font-size: 16px; font-weight: 600; line-height: 24px; overflow: hidden; display: -webkit-box; text-overflow: ellipsis; -webkit-box-orient: vertical; -webkit-line-clamp: 2;">article title</div><div style="padding: 4px 16px 12px; color: rgb(108, 107, 128); font-size: 14px; max-height: 48px; font-weight: 400; line-height: 24px; overflow: hidden; display: -webkit-box; text-overflow: ellipsis; -webkit-box-orient: vertical; -webkit-line-clamp: 2;"><p>article_detail</p></div><a href="%s" title="faq" target="_blank" style="box-sizing: border-box; margin-top: 8px; text-decoration: none; padding: 8px 16px; background: rgb(243, 243, 246); color: rgb(44, 35, 229); font-size: 14px; font-family: Inter; line-height: 22px; width: 100%; border-radius: 0px 0px 8px 8px; display: inline-block;">View all →</a></div>","attachmentList":[]}' % \ content = r'{"contentList":"<div data-type="willdesk-faq" style="background: rgb(255, 255, 255); border-radius: 8px; min-width: 230px; max-width: 100%; width: 300px; box-sizing: border-box; position: relative; border: 0.5px solid rgb(229, 229, 235);"><div style="padding: 12px 16px 0px; color: rgb(18, 17, 39); font-size: 16px; font-weight: 600; line-height: 24px; overflow: hidden; display: -webkit-box; text-overflow: ellipsis; -webkit-box-orient: vertical; -webkit-line-clamp: 2;">article title</div><div style="padding: 4px 16px 12px; color: rgb(108, 107, 128); font-size: 14px; max-height: 48px; font-weight: 400; line-height: 24px; overflow: hidden; display: -webkit-box; text-overflow: ellipsis; -webkit-box-orient: vertical; -webkit-line-clamp: 2;"><p>article_detail</p></div><a href="%s" title="faq" target="_blank" style="box-sizing: border-box; margin-top: 8px; text-decoration: none; padding: 8px 16px; background: rgb(243, 243, 246); color: rgb(44, 35, 229); font-size: 14px; font-family: Inter; line-height: 22px; width: 100%; border-radius: 0px 0px 8px 8px; display: inline-block;">View all →</a></div>","attachmentList":[]}' %data['content']
data['content']
elif data['type'] == 'rate': elif data['type'] == 'rate':
content = r'[&*{"reviewContent":"<p>Would you mind sharing your feedback on your experience so fa222r?</p>","thumbsReviews":{"good":"","bad":"FeedbackURL"},"startReviews":{"one_start":"FeedbackURL","two_start":"FeedbackURL","three_start":"FeedbackURL","four_start":"","five_start":"www.baidu.com"},"reviewTitle":"How was your chat with {AgentName}222?","reviewChoose":"thumbs","askSendReview":"true","autoSendReview":"false","primaryColor":"#2C23E5"}]' content = r'[&*{"reviewContent":"%s","thumbsReviews":{"good":"","bad":"FeedbackURL"},"startReviews":{"one_start":"FeedbackURL","two_start":"FeedbackURL","three_start":"FeedbackURL","four_start":"","five_start":"www.baidu.com"},"reviewTitle":"%s","reviewChoose":"thumbs","askSendReview":"true","autoSendReview":"false","primaryColor":"#2C23E5"}]'%(livechatData.rateContent,livechatData.rateTitle)
msgType = 'rate' msgType = 'rate'
elif data['type'] == 'link': elif data['type'] == 'link':
content = r'{"contentList":"<a class="wd-chat-link" data-type="willdesk-link" href="https://www.baidu.com" contenteditable="false" target="_blank">test</a>","attachmentList":[]}' content = "{\"contentList\":\"<a class=\\\"wd-chat-link\\\" data-type=\\\"willdesk-link\\\" href=\\\"%s\\\" contenteditable=\\\"false\\\" target=\\\"_blank\\\">%s</a>\",\"attachmentList\":[]}"%(livechatData.linkHref,livechatData.linkTitle)
elif data['type'] == 'product': elif data['type'] == 'product':
content = r'{"contentList":"<a href="https://zhs-test.myshopify.com/products/selling-plans-ski-wax" title="https://zhs-test.myshopify.com/products/selling-plans-ski-wax" data-type="willdesk-product" target="_blank" style="display: flex; background: rgb(255, 255, 255); border-radius: 8px; min-height: 80px; max-height: 150px; min-width: 100px; max-width: 100%; width: 300px; box-sizing: border-box; position: relative; text-decoration: none; padding: 12px 16px; border: 1px solid rgb(231, 233, 236);"><img src="https://cdn.shopify.com/s/files/1/0690/4551/8586/products/snowboard_wax.png?v=1708331992" style="width: 110px; height: 110px; max-height: 150px; object-fit: cover; border-radius: 8px; margin-right: 4%; flex-shrink: 0; border: 0.5px solid rgb(231, 233, 236);"><div style="width: calc(100% - 118px); display: flex; flex-direction: column; position: relative; justify-content: center;"><div style="width: 100%; max-height: 48px; line-height: 24px; color: rgb(18, 17, 39); font-size: 14px; font-weight: bold; overflow: hidden; display: -webkit-box; text-overflow: ellipsis; -webkit-box-orient: vertical; -webkit-line-clamp: 2;">Selling Plans Ski Wax</div></div></a>","attachmentList":[]}' content = "{\"contentList\":\"<a href=\\\"https://zhs-test.myshopify.com/products/selling-plans-ski-wax\\\" title=\\\"https://zhs-test.myshopify.com/products/selling-plans-ski-wax\\\" data-type=\\\"willdesk-product\\\" target=\\\"_blank\\\" style=\\\"display: flex; background: rgb(255, 255, 255); border-radius: 8px; min-height: 80px; max-height: 150px; min-width: 100px; max-width: 100%; width: 300px; box-sizing: border-box; position: relative; text-decoration: none; padding: 12px 16px; border: 1px solid rgb(231, 233, 236);\\\"><img src=\\\"https://cdn.shopify.com/s/files/1/0690/4551/8586/products/snowboard_wax.png?v=1708331992\\\" style=\\\"width: 110px; height: 110px; max-height: 150px; object-fit: cover; border-radius: 8px; margin-right: 4%; flex-shrink: 0; border: 0.5px solid rgb(231, 233, 236);\\\"><div style=\\\"width: calc(100% - 118px); display: flex; flex-direction: column; position: relative; justify-content: center;\\\"><div style=\\\"width: 100%; max-height: 48px; line-height: 24px; color: rgb(18, 17, 39); font-size: 14px; font-weight: bold; overflow: hidden; display: -webkit-box; text-overflow: ellipsis; -webkit-box-orient: vertical; -webkit-line-clamp: 2;\\\">Selling Plans Ski Wax</div></div></a>\",\"attachmentList\":[]}"
elif data['type'] == 'coupon': elif data['type'] == 'coupon':
content = r'{"contentList":"<a class="wd-chat-link" data-type="willdesk-link" href="https://tt-zldev003.myshopify.com/discount/V-0QE73BP5" contenteditable="false" style="margin-right: 8px" target="_blank">优惠券</a>","attachmentList":[]}' content = r'{"contentList":"<a class="wd-chat-link" data-type="willdesk-link" href="https://tt-zldev003.myshopify.com/discount/V-0QE73BP5" contenteditable="false" style="margin-right: 8px" target="_blank">优惠券</a>","attachmentList":[]}'
fromId = data['fromId'] if data.get('fromId') else getattr(Global, 'customerId') fromId = data['fromId'] if data.get('fromId') else getattr(Global, 'customerId')
...@@ -117,13 +118,16 @@ def ws_send_handler(case,ws): ...@@ -117,13 +118,16 @@ def ws_send_handler(case,ws):
uid = data['uid'] if data.get('uid') else getattr(Global, 'userId') uid = data['uid'] if data.get('uid') else getattr(Global, 'userId')
username = data['username'] if data.get('username') else getattr(Global, 'name') username = data['username'] if data.get('username') else getattr(Global, 'name')
isNote = data['isNote'] if data.get('isNote') else False isNote = data['isNote'] if data.get('isNote') else False
roomId = data['roomId'] roomId = str(data['roomId']) if ws.attr == 'willdesk' else ''
messageData = { avatar = 'https://img.willdesk.com/${picUrl}' if ws.attr == 'willdesk' else ''
'action': 'sendmsg', if ws.client_id == '':
'data': { await ws.get_client_id()
'avatar': "https://img.willdesk.com/${picUrl}", client_id = ws.client_id
'clientId': ws.client_id, if ws.attr == 'willdesk':
'fromId': fromId, # c端userId data = {
'avatar': avatar,
'clientId': client_id,
'fromId': str(fromId), # c端userId
'isNote': isNote, 'isNote': isNote,
'message': content, 'message': content,
'msgType': msgType, 'msgType': msgType,
...@@ -131,15 +135,34 @@ def ws_send_handler(case,ws): ...@@ -131,15 +135,34 @@ def ws_send_handler(case,ws):
'roomChannelType': 'wk', 'roomChannelType': 'wk',
'roomId': roomId, 'roomId': roomId,
'roomPlatform': 'willdesk', 'roomPlatform': 'willdesk',
'siteId': siteId, # 店铺id 'siteId': str(siteId), # 店铺id
'uType': 2, 'uType': 2,
'uid': uid, # userId 'uid': str(uid), # userId
'username': username # 品牌名称 'username': username # 品牌名称
}, }
else:
data = {
'avator': avatar,
'clientId': client_id,
'isNote': isNote,
'message': content,
'msgType': msgType,
'pageUrl': 'https://zhs-test.myshopify.com/',
'platform': 1,
'roomId': roomId,
'sendTime': int(time.time()),
'siteId': str(siteId), # 店铺id
'uType': 1,
'uid': str(fromId), # userId
'username': Global.customerName # 品牌名称
}
messageData = {
'action': 'sendmsg',
'data': data,
'seq': str(random.randint(1000000000000000, 9999999999999999)) 'seq': str(random.randint(1000000000000000, 9999999999999999))
} }
await ws.send_message(message=json.dumps(messageData)) await ws.send_message(message=json.dumps(messageData))
response = eval(await ws.receive_message()) response = json.loads(await ws.receive_message())
return response return response
def ws_assert(expected,msg): def ws_assert(expected,msg):
...@@ -148,10 +171,6 @@ def ws_assert(expected,msg): ...@@ -148,10 +171,6 @@ def ws_assert(expected,msg):
:param res: 返回的信息 :param res: 返回的信息
:return: :return:
''' '''
try:
msg = eval(msg)
except Exception:
return 0
for item in expected: # 循环每一个断言场景 for item in expected: # 循环每一个断言场景
for item_key, item_value in item.items(): for item_key, item_value in item.items():
assert_way = item_key assert_way = item_key
...@@ -169,39 +188,45 @@ def ws_assert(expected,msg): ...@@ -169,39 +188,45 @@ def ws_assert(expected,msg):
elif assert_way == 'ain': elif assert_way == 'ain':
assert res_path_value in value assert res_path_value in value
def ws_run(ws,case):
async def ws_run(ws,case):
''' '''
:param ws: 传入websocket服务 :param ws: 传入websocket服务
:param case: 传入用例数据 :param case: 传入用例数据
''' '''
loop = asyncio.get_event_loop() # asyncio.run(ws_action(ws=ws,case=case))
loop.run_until_complete(ws_action(ws=ws,case=case)) task = asyncio.ensure_future(ws_action(ws=ws,case=case))
await asyncio.wait_for(task,timeout=10)
# loop.run_until_complete(ws_action(ws=ws,case=case))
# 使用示例 # 使用示例
# async def main(): # async def main():
# data = json.dumps({ # data = json.dumps({
# 'action': "sendmsg", # 'action': "sendmsg",
# 'data': { # 'data': {
# 'avatar': "https://img.willdesk.com/${picUrl}", # 'avator': "",
# 'clientId': 'cnk14g7fot40rbaaqa20', # 'clientId': 'cnkm29etjph80j73niq0',
# 'fromId': '35948',
# 'isNote': False, # 'isNote': False,
# 'message': '{"contentList":"testtesttest<br>","attachmentList":[]}', # 'message': '{"contentList":"testtesttest<br>","attachmentList":[]}',
# 'msgType': 'newstext', # 'msgType': 'newstext',
# 'platform': 1, # 'platform': 1,
# 'roomChannelType': 'wk', # 'roomId': '',
# 'roomId': '502856393624136484',
# 'roomPlatform': 'willdesk',
# 'siteId': '7238', # 'siteId': '7238',
# 'uType': 2, # 'uType': 1,
# 'uid': '5746', # 'sendTime': int(time.time()),
# 'uid': '36202',
# 'username': 'zhs' # 'username': 'zhs'
# }, # },
# 'seq' : str(random.randint(1000000000000000, 9999999999999999)) # 'seq' : str(random.randint(1000000000000000, 9999999999999999))
# }) # })
# webs = ws(url=f'wss://atestws.sealapps.com/ws?platform=1&authorization=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MDk3MDc4NDAsImlzcyI6IndpbGxkZXNrLmNvbSIsInN1YiI6IkxvZ2luQXV0aFRva2VuIiwidXNlcl9pbmZvIjp7ImNvbXBhbnlJZCI6NjA1OSwiYnJhbmRJZCI6NjA1MiwiY3VzdG9tZXJTZXJ2aWNlSWQiOjU3NDYsImxvZ2luUm9sZSI6MSwiY2xpZW50SWQiOiJjbmsxNGc3Zm90NDByYmFhcWEyMCIsImxvZ2luVGltZSI6MTcwOTcwNzg0MH0sImtleSI6ImFsbHBsYXRmb3JtLXdpbGxkZXNrLXVzZXIifQ.XcTxOOmKaSQDGSiZIHfx6AB83c0qlo8kzs2zQpV-XDw&t=1709710166112',attr='willdesk') # webs = ws(url=f'wss://atestws.sealapps.com/ws?platform=1&authorization=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MDk3NzY4OTgsImlzcyI6IndpbGxkZXNrLmNvbSIsInN1YiI6IkxvZ2luQXV0aFRva2VuIiwidXNlcl9pbmZvIjp7ImNvbXBhbnlJZCI6NjA1OSwiYnJhbmRJZCI6NjA1MiwiY3VzdG9tZXJTZXJ2aWNlSWQiOjU3NDYsImxvZ2luUm9sZSI6MSwiY2xpZW50SWQiOiJjbmtpMDBnNmxnY2M3MWNxZHM1ZyIsImxvZ2luVGltZSI6MTcwOTc3Njg5OH0sImtleSI6ImFsbHBsYXRmb3JtLXdpbGxkZXNrLXVzZXIifQ.EllFwfirKFTB88BzBigz64tBz1SJQFFwFp0tWlQzWVU&t=1709802959971',attr='willdesk')
# await asyncio.create_task(webs.send_message(message=data)) # await asyncio.create_task(webs.send_message(message=data))
# msg = await asyncio.create_task(webs.receive_message()) # msg = await asyncio.create_task(webs.receive_message())
# print(msg)
# #
# loop = asyncio.get_event_loop() # loop = asyncio.get_event_loop()
# loop.run_until_complete(main()) # loop.run_until_complete(main())
...@@ -6,77 +6,77 @@ api1: ...@@ -6,77 +6,77 @@ api1:
set_value: {"picUrl" : "$.data.list[?(@.id == '${userId}')].profile"} set_value: {"picUrl" : "$.data.list[?(@.id == '${userId}')].profile"}
expected: expected:
- eq: {"$.code" : 0} - eq: {"$.code" : 0}
#
#api2: api2:
# title: 更改账户名 title: 更改账户名
# url: /api/v1/customerService/updateCustomerServiceAccount url: /api/v1/customerService/updateCustomerServiceAccount
# method: post method: post
# data: {"id" : "${userId}" , "localLang" : "zh-CN" ,"name" : "${new_name}" , "profile" : "${picUrl}", "v" : "${v}"} data: {"id" : "${userId}" , "localLang" : "zh-CN" ,"name" : "${new_name}" , "profile" : "${picUrl}", "v" : "${v}"}
# expected: expected:
# - eq: {"$.code" : 0} - eq: {"$.code" : 0}
# - eq: {"$.msg" : "success"} - eq: {"$.msg" : "success"}
#
#api3: api3:
# title: 检查用户名 title: 检查用户名
# url: /api/v1/customerService/listCustomerService url: /api/v1/customerService/listCustomerService
# method: post method: post
# data: {"isActivation" : -1,"isDelete" : -1,"v" : "${v}"} data: {"isActivation" : -1,"isDelete" : -1,"v" : "${v}"}
# expected: expected:
# - eq: {"$.code" : 0} - eq: {"$.code" : 0}
# - eq: {"$.data.list[?(@.id == '${userId}')].name" : "${new_name}"} - eq: {"$.data.list[?(@.id == '${userId}')].name" : "${new_name}"}
#
#api4: api4:
# title: 检查用户名 - 首页查询账户信息接口 title: 检查用户名 - 首页查询账户信息接口
# url: /api/v1/customerService/getCustomerServiceInfo?v=${v} url: /api/v1/customerService/getCustomerServiceInfo?v=${v}
# method: get method: get
# expected: expected:
# - eq: { "$.code": 0 } - eq: { "$.code": 0 }
# - eq: { "$.data.name": "${new_name}" } - eq: { "$.data.name": "${new_name}" }
#
#api5: api5:
# title: 检查用户名 - inbox页面检查资源列表接口 title: 检查用户名 - inbox页面检查资源列表接口
# url: /api/v1/resource/getResourceItemList url: /api/v1/resource/getResourceItemList
# method: post method: post
# data: {"resourceType" : "teammates" , "v" : "${v}"} data: {"resourceType" : "teammates" , "v" : "${v}"}
# expected: expected:
# - eq: {"$.code" : 0} - eq: {"$.code" : 0}
# - eq: {"$.data.list[?(@.relId == '${userId}')].name" : "${new_name}"} - eq: {"$.data.list[?(@.relId == '${userId}')].name" : "${new_name}"}
#
#api6: api6:
# title: 更改用户的设置语言 title: 更改用户的设置语言
# url: /api/v1/customerService/updateCustomerServiceAccount url: /api/v1/customerService/updateCustomerServiceAccount
# method: post method: post
# data: {"id" : "${userId}" , "localLang" : "${target_language}" , "profile" : "${picUrl}", "v" : "${v}"} data: {"id" : "${userId}" , "localLang" : "${target_language}" , "profile" : "${picUrl}", "v" : "${v}"}
# after_sql: /account/account_selectLanguage.py after_sql: /account/account_selectLanguage.py
# expected: expected:
# - eq: {"$.code" : 0} - eq: {"$.code" : 0}
# - eq: {"$.msg" : "success"} - eq: {"$.msg" : "success"}
#
#api8: api8:
# title: 检查翻译文本接口 title: 检查翻译文本接口
# url: /api/v1/translate/transKeyValue url: /api/v1/translate/transKeyValue
# before_sql: /account/account_selectTransResult.py before_sql: /account/account_selectTransResult.py
# method: post method: post
# data: {"keyValue" : {"${trans_key}" : "${originValue}"},"targetLang" : "${target_language}","transType" : 1,"v" : "${v}"} data: {"keyValue" : {"${trans_key}" : "${originValue}"},"targetLang" : "${target_language}","transType" : 1,"v" : "${v}"}
# expected: expected:
# - eq: {"$.code": 0 } - eq: {"$.code": 0 }
# - eq: {"$.data.translated" : {"${trans_key}" : "${transValue}"}} - eq: {"$.data.translated" : {"${trans_key}" : "${transValue}"}}
#
#api9: api9:
# title: 检查翻译文本接口 - 2 title: 检查翻译文本接口 - 2
# url: /api/v1/translate/transText url: /api/v1/translate/transText
# method: post method: post
# data: {"targetLang" : "English","text" : ["${originValue}"]} data: {"targetLang" : "English","text" : ["${originValue}"]}
# expected: expected:
# - eq: {"$.code": 0 } - eq: {"$.code": 0 }
# - eq: {"$.data.translated" : ["${originValue}"]} - eq: {"$.data.translated" : ["${originValue}"]}
#
#
#api10: api10:
# title: 还原设置 title: 还原设置
# url: /api/v1/customerService/updateCustomerServiceAccount url: /api/v1/customerService/updateCustomerServiceAccount
# method: post method: post
# data: {"id" : "${userId}" , "localLang" : "${origin_language}" ,"name" : "${old_name}", "profile" : "${picUrl}", "v" : "${v}"} data: {"id" : "${userId}" , "localLang" : "${origin_language}" ,"name" : "${old_name}", "profile" : "${picUrl}", "v" : "${v}"}
# expected: expected:
# - eq: {"$.code" : 0} - eq: {"$.code" : 0}
# - eq: {"$.msg" : "success"} - eq: {"$.msg" : "success"}
import pytest import pytest
import time import asyncio
import os import os
from Utils.sql_handler import test_env_conn from Utils.sql_handler import test_env_conn
from Utils import websocket_handler
if __name__ == '__main__': if __name__ == '__main__':
tims_str = int(time.time()) try:
pytest.main(['-vs','TestCase/account',f'--alluredir=./allureReports','--clean-alluredir']) pytest.main(['-vs','TestCase/inbox',f'--alluredir=./allureReports','--clean-alluredir'])
os.system(f'allure generate ./allureReports -c') os.system(f'allure generate ./allureReports -c')
# os.system('allure open ./allureReports') # os.system('allure open ./allureReports')
test_env_conn.close_db() finally:
print('finally')
# test_env_conn.close_db()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment