Commit a10f87e2 authored by zhanhuasheng's avatar zhanhuasheng

1、增加用例

2、告警调整
parent 86f349c5
import pytest
from Utils import yaml_handler
from Utils import req_handler
from TestData.setting.tag_test_data import tagData
class TestTag:
yaml_path = r'setting/tag.yaml'
yaml_data = yaml_handler.yaml_handler.get_case(yaml_path)
@pytest.mark.flaky(reruns=tagData.rerun, reruns_delay=tagData.rerun_delay)
@pytest.mark.parametrize('case',yaml_data)
def test_tag(self,case):
req_handler.ReqHandler.send_requests(case=case,var_class=tagData)
from Utils.global_variate import Global
from Utils.mockData_handler import data_handler
class tagData(Global):
tag_name = 'autotest_tag%s'%data_handler.random_id()
tag_description = 'autotest_tag_description'
tag_color = '#DC2A2A'
new_tag_name = 'autotest_tag_new_name%s'%data_handler.random_id()
new_tag_color = '4C4B63'
new_tag_description = 'autotest_tag_new_description'
from Utils.sql_handler import test_env_conn
from Utils.mockData_handler import data_handler
from TestData.setting.tag_test_data import tagData
if hasattr(tagData, 'tag_id'):#先判断有没有创建tag成功
pass
else:
insert_tag_id = data_handler.random_id()
tag_insert_sql = f"""INSERT INTO willdesk.tag (id,name,created_by,sort,status,brand_id,pid,cate,color,description,created_at,updated_at) VALUES
({insert_tag_id},{tagData.tag_name},{tagData.userId},0,0,{tagData.brandId},'',0,{tagData.tag_color},{tagData.tag_description},'2024-05-06 18:05:04','2024-05-06 18:05:04');
"""
test_env_conn.execute_sql(sql=tag_insert_sql)
setattr(tagData, 'tag_id', insert_tag_id)
tag_select_sql = f'select * from tag where brand_id = {tagData.brandId}'
tag_select_result = test_env_conn.select_many_value(sql=tag_select_sql)
tag_num = len(tag_select_result)
setattr(tagData, 'tag_num', tag_num)
tag_location = 1
for tag in tag_select_result:
if tag['id'] == tagData.tag_id:
break
tag_location += 1
if tag_location <= 10:
page_num = 1
elif tag_location % 10 == 0:
page_num = tag_location / 10
else:
page_num = tag_location % 10 + 1
setattr(tagData, 'page_num', page_num)
\ No newline at end of file
from Utils.sql_handler import test_env_conn
from TestData.setting.tag_test_data import tagData
tag_select_sql = f'select * from tag where brand_id = {tagData.brandId}'
tag_select_result = test_env_conn.select_many_value(sql=tag_select_sql)
tag_location = 1
for tag in tag_select_result:
if tag['id'] == tagData.tag_id:
break
tag_location += 1
if tag_location <= 10:
page_num = 1
elif tag_location % 10 == 0:
page_num = tag_location / 10
else:
page_num = tag_location % 10 + 1
setattr(tagData, 'page_num', page_num)
tag_room_select_sql = f'select * from `im_room` where `cate_id` = {tagData.brandId} and `status` = 1 and `is_ignore` = 0 and room_type != 2 and last_msg_uid != {tagData.userId}'
tag_room_select_result = test_env_conn.select_one_value(sql=tag_room_select_sql)
room_id = tag_room_select_result['room_id']
user_id = tag_room_select_result['last_msg_uid']
setattr(tagData, 'room_id', str(room_id))
setattr(tagData, 'user_id', str(user_id))
......@@ -144,8 +144,8 @@ class ReqHandler:
assert res.status_code == 200 #先断言状态码是正确的
time = res.elapsed.total_seconds()
if time >= 5:
warnings.warn(f'接口响应时间过长,耗时{str(time)}秒',RuntimeWarning) #告警接口耗时过长
logger.error(f'接口响应时间过长,耗时{str(time)}秒')
warnings.warn(f'接口响应时间过长,耗时{str(time)},接口地址:{res.url}',RuntimeWarning) #告警接口耗时过长
logger.error(f'接口响应时间过长,耗时{str(time)},接口地址:{res.url}')
if isinstance(expected,list):
'''
穿进来的expected一定是 {"eq":{$.code : value}} 的形式,要断言的值一定是通过jsonpath去检索的
......
api1:
title: 创建标签
url: /api/v1/resource/tag/createTag
method: post
data: {"color":"${tag_color}","name":"${tag_name}","description":"${tag_description}","sort":0,"status":0,"brand_id":"${brandId}","pid":"","cate":0,"v":"${v}"}
set_value: {"tag_id": "$.data.id"}
expected:
- eq: {"$.code" : 0}
api2:
title: 获取标签列表
url: /api/v1/resource/tag/getTags
method: post
before_sql: setting/tag/tag_select.py
data: {"pageParam":{"page":"${page_num}","pageSize":10},"v":"${v}"}
expected:
- eq: {"$.code" : 0}
- eq: {"$.data.total": "${tag_num}"}
- eq: {"$.data.list[?(@.id == '${tag_id}')].name": "${tag_name}"}
- eq: {"$.data.list[?(@.id == '${tag_id}')].color": "${tag_color}"}
- eq: {"$.data.list[?(@.id == '${tag_id}')].description": "${tag_description}"}
api3:
title: 编辑标签信息
url: /api/v1/resource/tag/modifyTag
method: post
data: {"name":"${new_tag_name}","color":"${new_tag_color}","description":"${new_tag_description}","id":"${tag_id}","brand_id":"${brandId}","v":"${v}"}
expected:
- eq: {"$.code" : 0}
api4:
title: 检查是否编辑成功
url: /api/v1/resource/tag/getTags
method: post
before_sql: setting/tag/tag_select2.py
data: {"pageParam": {"page": "${page_num}","pageSize": 10},"v": "${v}"}
expected:
- eq: {"$.code": 0}
- eq: {"$.data.total": "${tag_num}"}
- eq: {"$.data.list[?(@.id == '${tag_id}')].name": "${new_tag_name}"}
- eq: {"$.data.list[?(@.id == '${tag_id}')].color": "${new_tag_color}"}
- eq: {"$.data.list[?(@.id == '${tag_id}')].description": "${new_tag_description}"}
api5:
title: 设置会话标签
url: /api/v1/resource/tag/createTagRel
method: post
data: {"tag_id":"${tag_id}","rel_id":"${room_id}","rel_type":2,"v":"${v}"}
expected:
- eq: {"$.code" : 0}
api6:
title: 设置用户标签
url: /api/v1/resource/tag/createTagRel
method: post
data: {"tag_id": "${tag_id}","rel_id": "${user_id}","rel_type": 1,"v": "${v}"}
expected:
- eq: {"$.code": 0}
api7:
title: 检查用户标签是否设置成功
url: /api/v1/resource/tag/getTagRelsByRelId
method: post
data: {"rel_id":"${user_id}","rel_type":1,"v":"${v}"}
expected:
- eq: {"$.code": 0}
- in_list: {"$.data.list[*].tagId": "${tag_id}"}
api8:
title: 检查会话标签是否设置成功
url: /api/v1/resource/tag/getTagRelsByRelId
method: post
data: {"rel_id":"${room_id}","rel_type":2,"v":"${v}"}
expected:
- eq: {"$.code": 0}
- in_list: {"$.data.list[*].tagId": "${tag_id}"}
api9:
title: 检查标签关联数量
url: /api/v1/resource/tag/getTags
method: post
data: {"pageParam": {"page": "${page_num}","pageSize": 10},"v": "${v}"}
expected:
- eq: {"$.code": 0}
- eq: {"$.data.list[?(@.id == '${tag_id}')].customerCount": 1}
- eq: {"$.data.list[?(@.id == '${tag_id}')].roomCount": 1}
api10:
title: 删除标签
url: /api/v1/resource/tag/deleteTag
method: post
data: {"id":"${tag_id}","v":"${v}"}
expected:
- eq: {"$.code" : 0}
api11:
title: 检查标签是否删除成功
url: /api/v1/resource/tag/getTags
method: post
data: {"pageParam": {"page": "${page_num}","pageSize": 10},"v": "${v}"}
expected:
- eq: {"$.code": 0}
- not_in_list: {"$.data.list[*].id": "${tag_id}"}
\ No newline at end of file
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