From edfc773d745b02263bff59244d4a0f0aef74a964 Mon Sep 17 00:00:00 2001 From: zhanhuasheng Date: Mon, 1 Apr 2024 17:58:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TestCase/customer/test_01_customer.py | 13 +++++ TestData/customer/customer_test_data.py | 7 +++ TestFile/customer/customer_delete.py | 5 ++ TestFile/customer/customer_select.py | 28 +++++++++ TestFile/inbox/ticketStatus_selectStatus.py | 5 +- Utils/req_handler.py | 2 + YamlCase/customer/customer.yaml | 64 +++++++++++++++++++++ YamlCase/inbox/ticketStatus.yaml | 1 + 8 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 TestCase/customer/test_01_customer.py create mode 100644 TestData/customer/customer_test_data.py create mode 100644 TestFile/customer/customer_delete.py create mode 100644 TestFile/customer/customer_select.py create mode 100644 YamlCase/customer/customer.yaml diff --git a/TestCase/customer/test_01_customer.py b/TestCase/customer/test_01_customer.py new file mode 100644 index 0000000..c7c3eae --- /dev/null +++ b/TestCase/customer/test_01_customer.py @@ -0,0 +1,13 @@ +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 diff --git a/TestData/customer/customer_test_data.py b/TestData/customer/customer_test_data.py new file mode 100644 index 0000000..bc6bed3 --- /dev/null +++ b/TestData/customer/customer_test_data.py @@ -0,0 +1,7 @@ +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' diff --git a/TestFile/customer/customer_delete.py b/TestFile/customer/customer_delete.py new file mode 100644 index 0000000..7753157 --- /dev/null +++ b/TestFile/customer/customer_delete.py @@ -0,0 +1,5 @@ +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 diff --git a/TestFile/customer/customer_select.py b/TestFile/customer/customer_select.py new file mode 100644 index 0000000..7bde8f5 --- /dev/null +++ b/TestFile/customer/customer_select.py @@ -0,0 +1,28 @@ +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 diff --git a/TestFile/inbox/ticketStatus_selectStatus.py b/TestFile/inbox/ticketStatus_selectStatus.py index db6fa83..57f306b 100644 --- a/TestFile/inbox/ticketStatus_selectStatus.py +++ b/TestFile/inbox/ticketStatus_selectStatus.py @@ -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' diff --git a/Utils/req_handler.py b/Utils/req_handler.py index 66cdc8a..50e3870 100644 --- a/Utils/req_handler.py +++ b/Utils/req_handler.py @@ -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 diff --git a/YamlCase/customer/customer.yaml b/YamlCase/customer/customer.yaml new file mode 100644 index 0000000..f237e1c --- /dev/null +++ b/YamlCase/customer/customer.yaml @@ -0,0 +1,64 @@ +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 diff --git a/YamlCase/inbox/ticketStatus.yaml b/YamlCase/inbox/ticketStatus.yaml index 4eec9f8..78978b4 100644 --- a/YamlCase/inbox/ticketStatus.yaml +++ b/YamlCase/inbox/ticketStatus.yaml @@ -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: 分配一个会话给自己 -- GitLab