Browse Source

新增功能

“蒋伟” 1 year ago
parent
commit
78b10d1013

+ 8 - 6
DingDing.py

@@ -6,7 +6,7 @@ import datetime
 # 获取jenkins构建信息和本次报告地址
 import jenkins  # 安装pip install python-jenkins
 
-from common.yaml_util import read_config_yaml
+from common.yaml_util import read_config_yaml, read_yaml_out_time_url, write_yaml_out_time_url
 
 # 获取本机IP
 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -67,7 +67,8 @@ def DingTalkSend(info):
     print('通过数量:{}'.format(status_passed))
     status_failed = d.get('launch_status_failed')  # 不通过数量
     print('不通过数量:{}'.format(status_failed))
-
+    out_time_url = str(read_yaml_out_time_url())
+    print(out_time_url)
     # 钉钉推送
     text = (
                    f"<font color=\'#FFA500\'>[通知] </font>青春重庆-{info}报告"
@@ -75,11 +76,12 @@ def DingTalkSend(info):
                    # "\n\n用例未执行数: " + status_defects +
                    "\n\n用例通过数量: " + status_passed +
                    '''\n\n<font>用例失败数量: </font><font color=\'#FF0000\' size=2>%s</font> \n\n''' +
+                    "\n\n响应超过2s接口汇总:"+ out_time_url+
                    # "\n\n构建地址:\n" + job_url +
                    "\n\n测试报告地址: \n" + report_url +
                    "\n\n播报时间: " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) % (status_defects)
 
-    dd_robot = DingtalkChatbot(read_config_yaml("dingding", "prod_webhook"))
+    dd_robot = DingtalkChatbot(read_config_yaml("dingding", "test_yunwin_webhook"))
     ret = dd_robot.send_markdown(title='青春重庆', text=text, is_at_all=False)
     print(ret)
 
@@ -93,12 +95,12 @@ def dingtalk_send_warning(msg):
     try:
         res_time = round(msg.elapsed.total_seconds() * 1000, 2)
         text = f"<font color=\'#FFA500\'>[通知] </font>青春重庆-报警"\
-               f"\n\n>请求接口路径: {msg.url}% " \
-               f"\n\n>请求体: {str(msg.request.body).replace('%','')}% "\
+               f"\n\n>请求接口路径: {msg.url} " \
+               f"\n\n>请求体: {str(msg.request.body).replace('%','')} "\
                f"\n\n>接口响应时间: {res_time}毫秒 " \
                f"\n\n>播报时间: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} "
 
-        dd_robot = DingtalkChatbot('')
+        dd_robot = DingtalkChatbot(read_config_yaml("dingding", "prod_webhook"))
         dd_robot.send_markdown(title='青春重庆', text=text, is_at_all=False)
     except Exception as e:
         raise e

+ 10 - 8
common/request_util.py

@@ -7,7 +7,7 @@ import requests
 from DingDing import dingtalk_send_warning
 from common.database_util import DatabaseUtil
 from common.log_util import error_log, logs, warring_log
-from common.yaml_util import write_yaml, read_yaml, read_config_yaml, write_yaml_projectCode
+from common.yaml_util import write_yaml, read_yaml, read_config_yaml, write_yaml_out_time_url
 from random1111 import DubugTalk
 
 
@@ -114,15 +114,17 @@ class RequestUtil:
                     # 获取接口的请求时间
                     res_time = round(res.elapsed.total_seconds() * 1000, 2)
                     act_time = read_config_yaml("request", "request_out_time")
-                    print("act_time============",act_time)
-                    print("res_time============",res_time)
+                    print("act_time============", act_time)
+                    print("res_time============", res_time)
+
                     # 判断响应时间
                     if res_time >= act_time:
-                        warring_log(
-                            "接口实际请求时间{res_time}毫秒,请求时间大于{act_time}毫秒,请关注".format(res_time=res_time,
-                                                                                                 act_time=act_time))
-                        # 超时发送钉钉推送
-                        dingtalk_send_warning(res)
+                        # warring_log(
+                        #     "接口实际请求时间{res_time}毫秒,请求时间大于{act_time}毫秒,请关注".format(res_time=res_time,
+                        #                                                                          act_time=act_time))
+                        # # 超时发送钉钉推送
+                        # dingtalk_send_warning(res)
+                        write_yaml_out_time_url({name: res.url})
 
                     # print(res.json())
                     return_text = res.text

+ 14 - 19
common/yaml_util.py

@@ -17,10 +17,6 @@ def read_yaml(key):
 
 
 # 读取
-def read_yaml_projectCode(key):
-    with open(os.getcwd() + '/projectCode.yaml', mode='r', encoding='utf-8') as f:
-        value = yaml.load(stream=f, Loader=yaml.FullLoader)
-        return value[key]
 
 
 # 写入
@@ -31,26 +27,12 @@ def write_yaml(data):
         return value
 
 
-# 写入
-
-def write_yaml_projectCode(data):
-    with open(os.getcwd() + '/projectCode.yaml', mode='a', encoding='utf-8') as f:
-        value = yaml.dump(data, stream=f, allow_unicode=True)
-        return value
-
-
 # 清空
 def clear_yaml():
     with open(os.getcwd() + '/extract.yaml', mode='w', encoding='utf-8') as f:
         f.truncate()
 
 
-# 清空projectCode.yaml
-def clear_yaml_projectCode():
-    with open(os.getcwd() + '/projectCode.yaml', mode='w', encoding='utf-8') as f:
-        f.truncate()
-
-
 # 读取测试用列
 def read_testcase(yaml_path):
     with open(yaml_path, mode='r', encoding='utf-8') as f:
@@ -65,6 +47,18 @@ def read_config_yaml(one_node, two_nede):
         return value[one_node][two_nede]
 
 
+def read_yaml_out_time_url():
+    with open(get_project_path() + '\\out_time_url.yaml', mode='r', encoding='utf-8') as f:
+        value = yaml.load(f, Loader=yaml.FullLoader)
+        return value
+
+
+def write_yaml_out_time_url(data):
+    with open(os.getcwd() + '/out_time_url.yaml', mode='a', encoding='utf-8') as f:
+        value = yaml.dump(data, stream=f, allow_unicode=True)
+        return value
+
+
 # #读取数据得yaml
 def read_data_yaml(yaml_path):
     with open(get_project_path() + yaml_path, mode='r', encoding='utf-8') as f:
@@ -77,5 +71,6 @@ def read_case(yaml_path):
         value = yaml.load(stream=f, Loader=yaml.FullLoader)
         return value
 
+
 if __name__ == '__main__':
-    print(os.path.abspath(os.getcwd().split("common")[0]))
+    print(os.path.abspath(os.getcwd().split("common")[0]))

+ 1 - 1
config.yaml

@@ -16,7 +16,7 @@ log:
 
 
 request:
-  request_out_time: 3000
+  request_out_time: 2000
 
 
 dingding:

+ 25 - 6
conftest.py

@@ -5,24 +5,43 @@ from pathlib import Path
 import pytest
 import requests
 
-from common.yaml_util import clear_yaml, clear_yaml_projectCode, read_testcase, read_config_yaml, write_yaml
+from common.yaml_util import clear_yaml, read_testcase, read_config_yaml, write_yaml
 
 path = Path(__file__).parent.glob("**/test_001_登录接口.yaml")
 for yaml_path1 in path:
-    yaml_path=yaml_path1
+    yaml_path = yaml_path1
+
+# path = Path(__file__).parent.glob("**/test_001_登录接口验证码.yaml")
+# for yaml_path1 in path:
+#     yzm_path = yaml_path1
+
 
 @pytest.fixture(scope="session", autouse=True)
 def clear_yam():
     clear_yaml()
     login_system(yaml_path)
 
+
 def login_system(yaml_path: Path):
     global i
     data = read_testcase(yaml_path)
     for i in data:
         method = i['request'].pop("method")
-        url =read_config_yaml("base", "base_qccq_sc")+ i['request'].pop("url")
-            # 发送请求
-        res = requests.request( method, url, **i['request'])
+        url = read_config_yaml("base", "base_qccq_sc") + i['request'].pop("url")
+        # 发送请求
+        res = requests.request(method, url, **i['request'])
         token = res.json()['data']["token"]
-        write_yaml({"token":token})
+        write_yaml({"token": token})
+
+
+# def  yzm_login(yzm_path):
+#     global i
+#     data = read_testcase(yzm_path)
+#     for i in data:
+#         method = i['request'].pop('method')
+#         url = read_config_yaml("base", "base_qccq_sc") + i['request'].pop("url")
+#         res = requests.request(method, url, **i['request'])
+#         print(111111111111111111,res)
+
+
+

+ 1 - 1
test_case/qccq/个人中心/test_006_个人中心-我的青创培训-我参与的-类型查询.yaml

@@ -1,5 +1,5 @@
   -
-    name: 个人中心-我的青创培训-青创阵地
+    name: 个人中心-我的青创培训-我参与的-类型查询
     request:
       method: get
       url: /api/service-app-second/auth/AppCqzdSpaceContentController/applyList

+ 1 - 1
test_case/qccq/个人中心/test_022_个人中心-我的需求.yaml

@@ -1,5 +1,5 @@
   -
-    name: 个人中心-我的青字号-我的活动
+    name: 个人中心-我的需求
     request:
       method: post
       url: /api/service-youthcall-iam/ycqYouthcallWorkOrder/auth/myPaginQuery

+ 1 - 1
test_case/qccq/团干部密切联系青年/test_004_团干部密切联系青年-录入.yaml

@@ -1,5 +1,5 @@
   -
-    name: 团干部密切联系青年-列表
+    name: 团干部密切联系青年-录入
     request:
       method: post
       url: /api/service-sysmgr/auth/PropertyController/pageValue

+ 1 - 1
test_case/qccq/青创空间/test_004_青创空间-共享配置.yaml

@@ -1,5 +1,5 @@
   -
-    name: 青创空间-侧重领域
+    name: 青创空间-共享配置
     request:
       method: post
       url: /api/service-sysmgr/auth/PropertyController/pageValue

+ 1 - 1
test_case/qccq/青创空间/test_005_青创空间-创智工场.yaml

@@ -1,5 +1,5 @@
   -
-    name: 青创空间-侧重领域
+    name: 青创空间-创智工厂
     request:
       method: get
       url: /api/service-app-second/auth/AppCqzdSpaceContentController/introduction