Commit edfc773d authored by zhanhuasheng's avatar zhanhuasheng

新增用例

parent d52e1d38
import pytest
from Utils import yaml_handler
from Utils import req_handler
from TestData.customer.customer_test_data import customerData
class TestCustomer:
yaml_path = r'customer\customer.yaml'
yaml_data = yaml_handler.yaml_handler.get_case(yaml_path)
@pytest.mark.parametrize('case',yaml_data)
def test_customer(self,case):
req_handler.ReqHandler.send_requests(case=case,var_class=customerData)
print(case)
\ No newline at end of file
from Utils.global_variate import Global
class customerData(Global):
customer_test_name = 'autotest_customer'
customer_test_email = 'autotest_customer@gmail.com'
customer_test_phone = '13611122222'
customer_test_note = 'autotest_note_msg'
from Utils.sql_handler import test_env_conn
from TestData.customer.customer_test_data import customerData
customer_delete_sql = f'delete from `customer` where id = {customerData.add_customer_id}'
test_env_conn.execute_sql(customer_delete_sql)
\ No newline at end of file
from Utils.sql_handler import test_env_conn
from TestData.customer.customer_test_data import customerData
customer_select_sql = f'select * from `customer` where brand_id = {customerData.brandId} and is_visitor = 0 and email != "" and email not like "%@willdeskvisitor.com%" order by create_at desc'
customer_select_result = test_env_conn.select_many_value(sql=customer_select_sql)
customer_num = len(customer_select_result)
customer = customer_select_result[0]
customer_id = customer['id']
customer_email = customer['email']
customer_name = customer['name']
customer_phone = customer['phone']
customer_location = customer['location']
customer_timezone = customer['time_zone']
customer_tag_select_sql = f'select * from `tag` where brand_id = {customerData.brandId}'
customer_tag_select_result = test_env_conn.select_one_value(sql=customer_tag_select_sql)
customer_tag_id = customer_tag_select_result['id']
customer_tag_name = customer_tag_select_result['name']
setattr(customerData, 'customer_num', customer_num)
setattr(customerData, 'customer_id', customer_id)
setattr(customerData, 'customer_email', customer_email)
setattr(customerData, 'customer_name', customer_name)
setattr(customerData, 'customer_phone', customer_phone)
setattr(customerData, 'customer_location', customer_location)
setattr(customerData, 'customer_timezone', customer_timezone)
setattr(customerData, 'customer_tag_id', customer_tag_id)
setattr(customerData, 'customer_tag_name', customer_tag_name)
\ No newline at end of file
......@@ -5,13 +5,14 @@ all_ticket_select_sql = f'select * from `im_room` where `cate_id` = {ticketStatu
your_ticket_select_sql = f'select * from `im_room` where `cate_id` = {ticketStatusData.brandId} and `status` = 1 and `allocation_uid` = {ticketStatusData.userId} and `is_ignore` = 0 and room_type != 2'
unread_ticket_select_sql = f'select * from `im_room` where `cate_id` = {ticketStatusData.brandId} and `status` = 1 and `read_status` = 1 and `is_ignore` = 0 and room_type != 2'
unassigned_ticket_select_sql = f'select * from `im_room` where `cate_id` = {ticketStatusData.brandId} and `status` = 1 and `allocation_uid` = 0 and `is_ignore` = 0 and room_type != 2'
chatbot_ticket_select_sql = f'select * from `im_room` where `cate_id` = {ticketStatusData.brandId} and `status` = 1 and `is_ignore` = 0 and room_type = 2'
all_ticket_num = len(test_env_conn.select_many_value(sql=all_ticket_select_sql))
your_ticket_num = len(test_env_conn.select_many_value(sql=your_ticket_select_sql))
unread_ticket_num = test_env_conn.select_many_value(sql=unread_ticket_select_sql)
unassigned_ticket_num = test_env_conn.select_many_value(sql=unassigned_ticket_select_sql)
chatbot_ticket_num = len(test_env_conn.select_many_value(sql=chatbot_ticket_select_sql))
setattr(ticketStatusData,'all_ticket_num',all_ticket_num)
setattr(ticketStatusData,'your_ticket_num',your_ticket_num)
......@@ -20,7 +21,7 @@ setattr(ticketStatusData,'unread_ticket_num',len(unread_ticket_num))
setattr(ticketStatusData,'unread_ticket_num_add',len(unread_ticket_num)+1)
setattr(ticketStatusData,'unassigned_ticket_num',len(unassigned_ticket_num))
setattr(ticketStatusData,'unassigned_ticket_num_minus',len(unassigned_ticket_num)-1)
setattr(ticketStatusData,'chatbot_ticket_num',chatbot_ticket_num)
setattr(ticketStatusData,'unassigned_ticket_id',unassigned_ticket_num[0]['room_id'])
read_ticket_select_sql = f'select * from `im_room` where `cate_id` = {ticketStatusData.brandId} and `status` = 1 and `read_status` = 2 and `room_platform` = "willdesk" and `is_ignore` = 0 and `site_id` = {ticketStatusData.shopId} and room_type != 2'
......
......@@ -154,6 +154,8 @@ class ReqHandler:
assert value in res_path_value
elif assert_way == 'ain':#ain代表返回值在断言值中
assert res_path_value in value
elif assert_way == 'exec':
exec(value)
except AssertionError:
print(f'期望值为{value}{type(value)}),实际返回值为{res_path_value}{type(res_path_value)}),完整的expected体为{expected}')
raise AssertionError
......
api1:
title: 检查顾客列表
url: /api/v1/customer/local/getBrandCustomers
method: post
data: {"pageParam":{"page":1,"pageSize":100},"v":"${v}"}
before_sql: customer/customer_select.py
expected:
- eq: {"$.code" : 0}
- eq: {"$.data.total" : "${customer_num}"}
- eq: {"$.data.list[?(@.id == '${customer_id}')].name" : "${customer_name}"}
- eq: {"$.data.list[?(@.id == '${customer_id}')].email" : "${customer_email}"}
- eq: {"$.data.list[?(@.id == '${customer_id}')].phone" : "${customer_phone}"}
- eq: {"$.data.list[?(@.id == '${customer_id}')].location" : "${customer_location}"}
- eq: {"$.data.list[?(@.id == '${customer_id}')].timeZone" : "${customer_timezone}"}
- exec: {"code" : "assert len(res.json()['data']['list']) == ${customer_num}"}
api2:
title: 新建一个顾客
url: /api/v1/customer/local/createCustomer
method: post
data: {"name":"${customer_test_name}","email":"${customer_test_email}","phone":"${customer_test_phone}","tagList":[],"noteList":[],"v":"${v}"}
set_value: {"add_customer_id" : "$.data.id"}
expected:
- eq: {"$.code" : 0}
api3:
title: 检查是否新增顾客成功
url: /api/v1/customer/local/getBrandCustomers
method: post
data: {"pageParam":{"page":1,"pageSize":100},"v":"${v}"}
after_sql: customer/customer_delete.py
expected:
- eq: {"$.code" : 0}
- eq: {"$.data.list[?(@.id == '${add_customer_id}')].name" : "${customer_test_name}"}
api4:
title: 更新顾客信息
url: /api/v1/customer/local/updateCustomer
method: post
data: {"name":"${customer_test_name}","email":"${customer_test_email}","phone":"${customer_test_phone}","tagList":["${customer_tag_id}"],"noteList":[{"note_msg":"${customer_test_note}"}],"saveTag":true,"saveNote":true,"id":"${customer_id}","userType":1,"v":"${v}"}
expected:
- eq: {"$.code" : 0}
api5:
title: 检查顾客信息是否更新成功
url: /api/v1/customer/local/getBrandCustomers
method: post
data: { "pageParam": { "page": 1,"pageSize": 100 },"v": "${v}" }
expected:
- eq: { "$.code": 0 }
- eq: { "$.data.list[?(@.id == '${customer_id}')].name": "${customer_test_name}"}
- eq: { "$.data.list[?(@.id == '${customer_id}')].email": "${customer_test_email}"}
- eq: { "$.data.list[?(@.id == '${customer_id}')].phone": "${customer_test_phone}"}
- in: { "$.data.list[?(@.id == '${customer_id}')].tagList[*].id": "${customer_tag_id}"}
- in: { "$.data.list[?(@.id == '${customer_id}')].tagList[?(@.id == '${customer_tag_id}')].name": "${customer_tag_name}"}
- in: { "$.data.list[?(@.id == '${customer_id}')].noteList[*].noteMsg": "${customer_test_note}"}
api6:
title: 恢复顾客信息
url: /api/v1/customer/local/updateCustomer
method: post
data: {"name":"${customer_name}","email":"${customer_email}","phone":"${customer_phone}","tagList":[],"noteList":[],"saveTag":true,"saveNote":true,"id":"${customer_id}","userType":1,"v":"${v}"}
expected:
- eq: {"$.code" : 0}
\ No newline at end of file
......@@ -10,6 +10,7 @@ api1:
- eq: {"$.data.list.assigned.openCount" : "${your_ticket_num}"}
- eq: {"$.data.list.unread.openCount" : "${unread_ticket_num}"}
- eq: {"$.data.list.unassigned.openCount" : "${unassigned_ticket_num}"}
- eq: {"$.data.list.chatbot.openCount" : "${chatbot_ticket_num}"}
api2:
title: 分配一个会话给自己
......
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