Browse Source

招标搜索筛选条件的校验添加删除

yuanyuan 4 months ago
parent
commit
3e5a0f15d0
2 changed files with 171 additions and 2 deletions
  1. 62 0
      cases/pc/登录功能/搜索功能/screen_filter.py
  2. 109 2
      lib/webapi.py

+ 62 - 0
cases/pc/登录功能/搜索功能/screen_filter.py

@@ -0,0 +1,62 @@
+from hytest import *
+from lib.webapi import apimgr
+
+
+# 校验筛选条件
+class c1:
+    name = '招标搜索筛选条件的校验添加删除'  # 测试用例名称
+
+    # 测试步骤
+    def teststeps(self):
+        INFO('测试步骤')
+        STEP(1, '第一步调用校验招标搜索筛选条件接口')  # 会出现在测试报告中
+        res1 = apimgr.check_search()  #调用招标搜索筛选条件的校验接口
+        actual1 = res1.json()  #调用校验接口的返回值转换为json格式
+        inkey = actual1["data"]  # 提取返回的 data 并保存
+        INFO(f"提取的筛选条件的inkey: {inkey}")  #打印提取到的data值
+        # 设置检查点
+        error_code1 = actual1["error_code"]
+        CHECK_POINT('检查校验筛选条件接口是否正常', error_code1 == 0)
+
+        STEP(2, '第二步调用保存招标搜索筛选条件接口')
+        res2 = apimgr.add_search(inkey)  #调用招标搜索筛选条件的新增接口
+        actual2 = res2.json()
+        # 设置检查点
+        error_code2 = actual2["error_code"]
+        CHECK_POINT('保存筛选条件接口是否正常', error_code2 == 0)
+
+        STEP(3, '第三步调用展示筛选条件接口')  # 会出现在测试报告中
+        res3 = apimgr.show_search()  #调用招标搜索筛选条件的展示接口
+        actual3 = res3.json()
+        # 检查 actual3["data"] 是否为列表
+        if isinstance(actual3["data"], list):
+            # 假设列表中第一个元素包含 "id" 字段
+            if len(actual3["data"]) > 0 and isinstance(actual3["data"][0], dict) and "id" in actual3["data"][0]:
+                id_value = actual3["data"][0]["id"]
+                INFO(f"提取的筛选条件的id: {id_value}")
+            else:
+                INFO("未找到有效的筛选条件id")
+                id_value = None  # 给 id_value 赋一个默认值
+        else:
+            # 如果 actual3["data"] 不是列表,尝试直接获取 "id"
+            if isinstance(actual3["data"], dict) and "id" in actual3["data"]:
+                id_value = actual3["data"]["id"]
+                INFO(f"提取的筛选条件的id: {id_value}")
+            else:
+                INFO("未找到有效的筛选条件id")
+                id_value = None  # 给 id_value 赋一个默认值
+
+        # 设置检查点
+        error_code3 = actual3["error_code"]
+        CHECK_POINT('展示筛选条件接口是否正常', error_code3 == 0)
+
+        # 在使用 id_value 之前,先检查其是否为 None
+        if id_value is not None:
+            STEP(4, '第四步调用删除筛选条件接口')
+            res4 = apimgr.del_search(id_value)  # 调用招标搜索筛选条件的删除接口
+            actual4 = res4.json()
+            error_code4 = actual4["error_code"]
+            CHECK_POINT('删除筛选条件接口是否正常', error_code4 == 0)
+        else:
+            INFO("由于未获取到有效的 id_value,跳过删除筛选条件步骤")
+

+ 109 - 2
lib/webapi.py

@@ -1420,7 +1420,7 @@ class APIMgr():
         return response
     #电销
     #个人信息查询
-    def personal_info(self):
+    def     personal_info(self):
         header = GSTORE['headers']
         session=self.get_session()
         json = {
@@ -1719,8 +1719,115 @@ class APIMgr():
         response = self.s.post(f"{cfg.target_host}/jyapi/jybx/core/participate/info",headers = headers , json = json)
         return response
 
+    #校验招标搜索筛选条件
+    def check_search(self):
+        headers = GSTORE['headers']
+        json = {
+            "bidField": "",
+            "searchvalue": "挖掘机",
+            "selectType": "content",
+            "industry": "建筑工程_勘察设计,建筑工程_工程施工,建筑工程_监理咨询,建筑工程_材料设备,建筑工程_机电安装,建筑工程_其他",
+            "minprice": "",
+            "maxprice": "",
+            "publishtime": "fiveyear",
+            "subtype": "招标结果",
+            "buyerclass": "",
+            "buyertel": "y",
+            "winnertel": "",
+            "notkey": "工地",
+            "buyer": "",
+            "winner": "",
+            "agency": "",
+            "fileExists": "1",
+            "regionMap": {
+                "河南": {}
+            },
+            "searchGroup": 0,
+            "searchMode": 1,
+            "wordsMode": 0,
+            "additionalWords": "",
+            "dateTime": "fiveyear"
+        }
+        response = self.s.post(f"{cfg.target_host}/jyapi/jybx/base/checkSearchScreen",headers = headers ,json = json)
+        return response
+
+    # 保存招标搜索筛选条件
+    def add_search(self,inkey):
+        check_response = self.check_search()
+        try:
+            check_data = check_response.json()
+            inkey_value = check_data.get('data')
+            if inkey_value:
+                headers = GSTORE['headers']
+                json = {
+                    "bidField": "",
+                    "searchvalue": "挖掘机",
+                    "selectType": "content",
+                    "industry": "建筑工程_勘察设计,建筑工程_工程施工,建筑工程_监理咨询,建筑工程_材料设备,建筑工程_机电安装,建筑工程_其他",
+                    "minprice": "",
+                    "maxprice": "",
+                    "publishtime": "fiveyear",
+                    "subtype": "招标结果",
+                    "buyerclass": "",
+                    "buyertel": "y",
+                    "winnertel": "",
+                    "notkey": "工地",
+                    "buyer": "",
+                    "winner": "",
+                    "agency": "",
+                    "fileExists": "1",
+                    "regionMap": {
+                        "河南": {}
+                    },
+                    "searchGroup": 0,
+                    "searchMode": 1,
+                    "wordsMode": 0,
+                    "additionalWords": "",
+                    "dateTime": "fiveyear",
+                    "inkey": inkey_value
+                }
+                response = self.s.post(f"{cfg.target_host}/jyapi/jybx/base/addSearchScreen", headers=headers, json=json)
+                return response
+            else:
+                print("未从 check_search 返回结果中找到 data 字段。")
+                return None
+        except ValueError:
+            print("无法将 check_search 的响应解析为 JSON。")
+            return None
 
-
+    #展示招标搜索筛选条件
+    def show_search(self):
+        headers = GSTORE['headers']
+        json = {
+            "bidField": ""
+        }
+        response = self.s.post(f"{cfg.target_host}/jyapi/jybx/base/showSearchScreen",headers = headers ,json = json)
+        return response
+
+    # 删除招标搜索筛选条件
+    def del_search(self,id_value):
+        show_response = self.show_search()
+        try:
+            show_data = show_response.json()
+            data = show_data.get('data')
+            if data and isinstance(data, list) and len(data) > 0:
+                search_id = data[0].get('id')
+                if search_id:
+                    headers = GSTORE['headers']
+                    json = {
+                        "id": search_id
+                    }
+                    response = self.s.post(f"{cfg.target_host}/jyapi/jybx/base/delSearchScreen", headers=headers, json=json)
+                    return response
+                else:
+                    print("未从 show_search 返回结果的 data 下找到 id 字段。")
+                    return None
+            else:
+                print("未从 show_search 返回结果中找到有效的 data 列表。")
+                return None
+        except ValueError:
+            print("无法将 show_search 的响应解析为 JSON。")
+            return None
 
 apimgr = APIMgr()