From 004c4fd65674238493b0ab6b06d0fe0cf9170b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=81=A5=E7=88=B8?= Date: Wed, 22 Feb 2023 16:42:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=AD=E8=A8=80contains=20?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E7=BB=93=E6=9E=9C=E6=98=AFjsonpath=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E6=89=80=E6=9C=89=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platpform_store/platform_index.yaml | 58 ++++++++++++++++++- .../platpform_store/test_platform_index.py | 4 +- .../JekunAuto_WeChat/user_login/test_login.py | 2 +- .../user_login/test_user_info.py | 2 +- utils/assertion/assert_control.py | 6 +- utils/assertion/assert_type.py | 4 +- utils/other_tools/models.py | 2 +- .../get_yaml_data_analysis.py | 2 +- 8 files changed, 67 insertions(+), 13 deletions(-) diff --git a/data/JekunAuto_WeChat/platpform_store/platform_index.yaml b/data/JekunAuto_WeChat/platpform_store/platform_index.yaml index a193385..29f9ef0 100644 --- a/data/JekunAuto_WeChat/platpform_store/platform_index.yaml +++ b/data/JekunAuto_WeChat/platpform_store/platform_index.yaml @@ -23,7 +23,7 @@ platform_index_01: fields: "id,categoryName,childCategories" thirdPartySource: JEKUNAUTO clientSource: "0" - dependence_case: True + dependence_case: False # 依赖的数据 dependence_case_data: - case_id: user_info_01 @@ -46,4 +46,58 @@ platform_index_01: type: == value: "车身护理" AssertType: - sql: \ No newline at end of file + sql: + + +platform_property_01: + host: ${{host()}} + url: /v1/service/service/property + method: get + detail: 获取商城筛选字段 + headers: + Connection: 'keep-alive' + clientSource: '0' + areaCode: '440105' + content-type: 'application/json' + requestType: params + is_run: + data: + fields: "goodsProperty,isNeedMatchCar,matchProperty,sort" + thirdPartySource: JEKUNAUTO + carLicense: + frontServiceId: 1 + dependence_case: + dependence_case_data: + + assert: + status_code: 200 + data: + jsonpath: $.data.* + type: contains + value: "价格从高至低" + AssertType: + sql: + +#platform-goods-list_01: +# host: ${{host()}} +# url: /v1/service/service/platform-goods-list +# method: get +# detail: 获取商品详情 +# headers: +# Connection: 'keep-alive' +# clientSource: '0' +# areaCode: '440105' +# content-type: 'application/json' +# requestType: params +# is_run: +# data: +# fields: "goodsProperty,isNeedMatchCar,matchProperty,sort" +# thirdPartySource: JEKUNAUTO +# carLicense: +# frontServiceId: 1 +# dependence_case: +# dependence_case_data: +# +# assert: +# status_code: 200 +# sql: \ No newline at end of file diff --git a/test_case/JekunAuto_WeChat/platpform_store/test_platform_index.py b/test_case/JekunAuto_WeChat/platpform_store/test_platform_index.py index 56f83cd..61b7484 100644 --- a/test_case/JekunAuto_WeChat/platpform_store/test_platform_index.py +++ b/test_case/JekunAuto_WeChat/platpform_store/test_platform_index.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# @Time : 2023-02-21 17:00:49 +# @Time : 2023-02-22 15:45:30 import allure @@ -12,7 +12,7 @@ from utils.read_files_tools.regular_control import regular from utils.requests_tool.teardown_control import TearDownHandler -case_id = ['platform_index_01'] +case_id = ['platform_index_01', 'platform_property_01'] TestData = GetTestCase.case_data(case_id) re_data = regular(str(TestData)) diff --git a/test_case/JekunAuto_WeChat/user_login/test_login.py b/test_case/JekunAuto_WeChat/user_login/test_login.py index 4ef9d6d..ee55af9 100644 --- a/test_case/JekunAuto_WeChat/user_login/test_login.py +++ b/test_case/JekunAuto_WeChat/user_login/test_login.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# @Time : 2023-02-21 17:00:49 +# @Time : 2023-02-22 15:45:30 import allure diff --git a/test_case/JekunAuto_WeChat/user_login/test_user_info.py b/test_case/JekunAuto_WeChat/user_login/test_user_info.py index 4f2fc8f..fedcf48 100644 --- a/test_case/JekunAuto_WeChat/user_login/test_user_info.py +++ b/test_case/JekunAuto_WeChat/user_login/test_user_info.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# @Time : 2023-02-21 17:00:49 +# @Time : 2023-02-22 15:45:30 import allure diff --git a/utils/assertion/assert_control.py b/utils/assertion/assert_control.py index bab1bed..fff2d9a 100644 --- a/utils/assertion/assert_control.py +++ b/utils/assertion/assert_control.py @@ -23,6 +23,7 @@ class Assert: # literal_eval()函数:会判断需要计算的内容计算后是不是合法的python类型,如果是则进行计算,否则不计算,就是去'' self.assert_data = ast.literal_eval(cache_regular(str(assert_data))) # 返回一个字典,{Key:value} value的类型是一个函数或者是一个@staticmethod的静态方法 + # {'equals': ,'less_than': , 'less_than_or_equals': } self.functions_mapping = load_module_functions(assert_type) @staticmethod @@ -115,6 +116,8 @@ class Assert: resp_data=resp_data, message=message ) + if len(resp_data) > 1: + str(resp_data) # 判断assertType为空的情况下,则走响应断言 elif assert_types is None: @@ -143,13 +146,10 @@ class Assert: assert status_code == values else: assert_value = self.assert_data[key]['value'] # 获取 yaml 文件中的期望value值 - print("---------yaml的断言数据assert_value:{}----------------".format(assert_value)) assert_jsonpath = self.assert_data[key]['jsonpath'] # 获取到 yaml断言中的jsonpath的数据 assert_types = self.assert_data[key]['AssertType'] - print("-----------assert_types:{}----------------".format(assert_types)) # 从yaml获取jsonpath,拿到对象的接口响应数据 resp_data = jsonpath(json.loads(response_data), assert_jsonpath) - print("-----------响应数据resp_data:{}----------------".format(resp_data)) message = self._message(value=values) # jsonpath 如果数据获取失败,会返回False,判断获取成功才会执行如下代码 if resp_data is not False: diff --git a/utils/assertion/assert_type.py b/utils/assertion/assert_type.py index ce48b62..169a52d 100644 --- a/utils/assertion/assert_type.py +++ b/utils/assertion/assert_type.py @@ -110,8 +110,8 @@ def length_less_than_or_equals( def contains(check_value: Any, expect_value: Any, message: Text = ""): """判断期望结果内容包含在实际结果中""" assert isinstance( - check_value, (list, tuple, dict, str, bytes) - ), "expect_value 需要为 list/tuple/dict/str/bytes 类型" + check_value, (list, tuple, dict, str, bytes, Text) + ), "expect_value 需要为 list/tuple/dict/str/bytes Text 类型" assert expect_value in check_value, message diff --git a/utils/other_tools/models.py b/utils/other_tools/models.py index 23fcf30..a9e3c8a 100644 --- a/utils/other_tools/models.py +++ b/utils/other_tools/models.py @@ -44,6 +44,7 @@ def load_module_functions(module) -> Dict[Text, Callable]: 原理:把字典对象转成可遍历对象,判断里面是否有fuction,再组装成字典返回 vars()内置函数:参数一个字典对象,返回一个字典 。itemns()操作字典函数:字典不可遍历,。items返回一个可遍历的对面,dict_items([('name', 'jack'), ('item', '1')]) + module_functions:{'equal':,'less_than':} """ module_functions = {} @@ -224,7 +225,6 @@ class AllureAttachmentType(Enum): PDF = "pdf" -# todo 分析断言,增加断言种类 @unique class AssertMethod(Enum): """断言类型""" diff --git a/utils/read_files_tools/get_yaml_data_analysis.py b/utils/read_files_tools/get_yaml_data_analysis.py index cf929e5..5722648 100644 --- a/utils/read_files_tools/get_yaml_data_analysis.py +++ b/utils/read_files_tools/get_yaml_data_analysis.py @@ -254,7 +254,7 @@ class CaseData: self.raise_value_null_error(case_id=case_id, data_name="dependence_case") ) from exc - # TODO 对 dependence_case_data 中的值进行验证 + # 对 dependence_case_data 中的值进行验证 def get_dependence_case_data( self, case_id: Text,