解决版本号过多,需要通过脚本添加

 

 1. 增加数据库连接

import pymysql
class ConnectMysql():
    """
    连接数据库
    """
    def connect_mysql(self):
        #打开数据库链接
        #获取一个数据库连接,注意如果是UTF-8类型的,需要制定数据库 #port 必须是数字不能为字符串
        db = pymysql.connect(host="host地址",user="用户名",password="密码",db="数据库名称",port=23306,charset='utf8')
        #使用cursor()
        cur = db.cursor()
        #1. 查询操作
        #编写查询语句bus_equipment对应我的表名
        sql = "SELECT digital_component_detail_id FROM digital_component_detail WHERE component_name='测试_10.25 10:40'"
        new_detail_id = []
        try:
            cur.execute(sql)        #执行sql语句
            results = cur.fetchall()        #获取查询的所有记录
            for i in results:
                new_detail_id.append(i[0])
            detailId = new_detail_id[-1]
        except Exception as e:
            raise e
        finally:
            db.close()
        return detailId

2. 发布版本接口,调用最新的detail_id

#coding:utf-8
import unittest,requests
from common.connect_mysql import ConnectMysql

cm = ConnectMysql()
class PublishDigitalDocuments(unittest.TestCase):
    '''数字组件发布'''
    def test_01(self):
        '''数字组件发布'''
        for i in range(0,30):
            # componentName = "test" + str(time.time())[-7:]
            componentName = "测试_10.25 10:40"
            detailId = cm.connect_mysql()
            print(detailId)
            payload1 = {
                "componentLabel": ["D002"],
                "componentName": componentName,
                "componentType": "D010",
                "componentValue": "{\"cid\":\"compId-x\",\"type\":\"component\",\"title\":\"组件名称\",\"eCodes\":[\"ecode-a\",\"ecode-b\",\"ecode-c\",\"ecode-d\"],\"values\":[{\"ecode-a\":\"ecode-a 数据\"},{\"ecode-b\":\"ecode-b 数据\"},{\"ecode-c\":\"ecode-c 数据\"},{\"ecode-d\":\"ecode-d 数据\"}]}",
                "enterpriseId": "1",
                "detailId":detailId,
                "keywords": ["关键词测试显示规则的", "测试数字组件数据更新"]
            }
            s = requests.session()
            #拼接请求地址
            url_api = "接口地址"
            #请求头部
            headers2 = {
            "Content-Type": "application/json",
             }
            r = s.post(url=url_api,headers=headers2,json=payload1)
            print(r.json())

if __name__=="__main__":
    unittest.main()

 

posted @ 2021-10-25 11:17  Camillezxl  阅读(45)  评论(0编辑  收藏  举报