浏览代码

JW第二次提交

“蒋伟” 1 年之前
父节点
当前提交
ccbfa402b0

+ 15 - 0
config.yaml

@@ -0,0 +1,15 @@
+#基础路径
+base:
+  base_cwt_url: http://172.19.0.185
+  base_wyxw_url: http://47.107.116.139
+  base_md5_url: http://127.0.0.1:5000
+  base_weixin_url: https://api.weixin.qq.com/cgi-bin
+  base_tzjs_url: https://ai.cq.189.cn/industrial-label
+  base_qccq_url: https://youth.cq.cqyl.org.cn:11020
+  base_qccq_tyy: http://221.229.99.73:63220/api
+
+#日志配置
+log:
+  log_name: logs_
+  log_level: info
+  log_format: '[%(asctime)s] %(filename)s->%(funcName)s line:%(lineno)d [%(levelname)s] %(message)s'

+ 8 - 0
conftest.py

@@ -0,0 +1,8 @@
+import pytest
+
+from common.yaml_util import clear_yaml, clear_yaml_projectCode
+
+
+@pytest.fixture(scope="session", autouse=True)
+def clear_yam():
+    clear_yaml()

+ 0 - 0
extract.yaml


+ 9 - 0
pytest.ini

@@ -0,0 +1,9 @@
+[pytest]
+addopts = -vs --alluredir=./temps --clean-alluredir
+testpaths = ./test_case/qccq
+;python_files = test_*.py
+;python_classes = Test*
+;python_functions = test
+;markers =
+;    smoke:冒烟
+;    usermanage:用户管理

+ 98 - 0
random1111.py

@@ -0,0 +1,98 @@
+import base64
+import hashlib
+import os
+import random
+import time
+
+# import rsa as rsa
+import yaml
+
+from common.request_util import *
+from common.yaml_util import read_yaml
+
+
+class DubugTalk:
+    # 获得随机数
+    def get_random_number(self, min, max):
+        return str(random.randint(int(min), int(max)))
+
+    def read_yaml(self, key):
+        return read_yaml(key)
+
+    # Md5加密
+    def md5(self, args):
+        # 以指定的编码格式编码字符串
+        utf8_str = str(args).encode("utf-8")
+        # MD5加密(哈稀算法)
+        md5_str = hashlib.md5(utf8_str).hexdigest()
+        return md5_str.upper()
+
+    # base64加密
+    def bs64(self, args):
+        # 以指定的编码格式编码字符串
+        utf8_str = str(args).encode("utf-8")
+        # base64加密
+        ba64_str = base64.b64encode(utf8_str).decode('utf-8')
+        return ba64_str.upper()
+
+    # RSA双钥加密
+    # # 生成公钥私钥到指定文件
+    # def create_key(self):
+    #     # 根据密钥长度生成公钥私钥
+    #     (public_key, private_key) = rsa.newkeys(1024)
+    #     # 报存公钥
+    #     with open("public.pem", "w+") as f:
+    #         f.write(public_key.save_pkcs1().decode())
+    #     # 报存私钥
+    #     with open("private.pem", "w+") as f:
+    #         f.write(private_key.save_pkcs1().decode())
+    # 通过公钥加密
+    # def public_key_jiami(self, args):
+    #     # 导入密钥
+    #     with open("public.pem") as f:
+    #         pubkey = rsa.PublicKey.load_pkcs1(f.read().encode())
+    #     # 加密
+    #     byte_str = rsa.encrypt(str(args).encode("utf-8"), pubkey)
+    #     # 把二进制转化成字符串格式
+    #     miwen = base64.b64encode(byte_str).decode("utf-8")
+    #     return miwen
+    # 通过私钥解密
+    # def private_key_jiemi(self,args):
+    #     with open("private.pem") as f:
+    #         prikey = rsa.PrivateKey.load_pkcs1(f.read().encode())
+    #     # 把字符串转换二进制
+    #     byte_key = base64.b64decode(args)
+    #     #解密
+    #     mingwen = rsa.decrypt(byte_key, prikey).decode()
+    #     return mingwen
+
+    # singe签名
+    def singes(self, yaml_path):
+        last_url = ""
+        last_data = {}
+        with open(os.getcwd() + yaml_path, encoding="utf-8") as f:
+            yaml_value = yaml.load(f, Loader=yaml.FullLoader)
+            for caseinfo in yaml_value:
+                # print(caseinfo)
+                caseinfo_keys = caseinfo.keys()
+                # 判断一级关键字是否存在:name,request,validate
+                if "request" in caseinfo_keys:
+                    # 判断url
+                    if "url" in caseinfo['request'].keys():
+                        last_url = caseinfo['request']['url']
+                        print(caseinfo['request']['url'])
+                    # 判断参数
+                    req = caseinfo['request']
+                    for key, value in req.items():
+                        if key in ["params", "data", "json"]:
+                            for p_key, p_value in req[key].items():
+                                last_data[p_key] = p_value
+        last_url = last_url[last_url.index("?") + 1:len(last_url)]
+        # 把url字典格式加入到last_data字典格式里面
+        lis = last_url.split("&")
+        print(lis)
+        for a in lis:
+            last_data[a[0:a.index('=')]] = a[a.index('=') + 1:len(a)]
+        from common.request_util import RequestUtil
+        # last_data = RequestUtil(self).replace_value(last_data)
+        print(last_data)

+ 29 - 0
requirements.txt

@@ -0,0 +1,29 @@
+allure-pytest==2.9.45
+allure-python-commons==2.9.45
+atomicwrites==1.4.0
+attrs==21.4.0
+certifi==2021.10.8
+charset-normalizer==2.0.12
+colorama==0.4.4
+execnet==1.9.0
+idna==3.3
+importlib-metadata==4.11.2
+iniconfig==1.1.1
+packaging==21.3
+pluggy==1.0.0
+py==1.11.0
+pyparsing==3.0.7
+pytest==7.0.1
+pytest-forked==1.4.0
+pytest-html==3.1.1
+pytest-metadata==1.11.0
+pytest-ordering==0.6
+pytest-rerunfailures==10.2
+pytest-xdist==2.5.0
+PyYAML==6.0
+requests==2.27.1
+six==1.16.0
+tomli==2.0.1
+typing_extensions==4.1.1
+urllib3==1.26.9
+zipp==3.7.0

+ 0 - 0
test_case/__init__.py


+ 0 - 0
test_case/jiangwei_demo/__init__.py


+ 27 - 0
test_case/jiangwei_demo/test_001_masjy.yaml

@@ -0,0 +1,27 @@
+
+-
+  name: $ddt{name}
+  request:
+    method: post
+    url: /token
+    data:
+      grant_type: $ddt{grant_type}
+      appid: $ddt{appid}
+      secret: $ddt{secret}
+  parameterize:
+    - [ 'name','grant_type','appid','secret','asser_str']
+    - ['成功获取鉴权码','client_credential','wxa64bb4f4d5a08047','9906f1cd88a1cb6f066468b697d8aa5b',access_token]
+    - ['client_credential为空','','wxa64bb4f4d5a08047','9906f1cd88a1cb6f066468b697d8aa5b',40002]
+    - ['appid为空','client_credential','','9906f1cd88a1cb6f066468b697d8aa5b',41002]
+    - ['secret为空','client_credential','wxa64bb4f4d5a08047','',41004]
+  extract:
+    token: '"access_token":"(.*?)"'
+    token1: $.access_token
+  validate:
+    - contains: $ddt{asser_str}
+#    - db_equals: {"select * from uisql":expires_in}
+#    - equals: {'expires_in':7200}
+
+
+
+

+ 19 - 0
test_case/jiangwei_demo/test_002_masjy.yaml

@@ -0,0 +1,19 @@
+
+-
+  name: 获取公众号已创建的标签接口
+  request:
+    method: post
+    url: /tags/get
+    data:
+      access_token: ${read_yaml(token)}
+  extract:
+    token: '"access_token":"(.*?)"'
+    token1: $.access_token
+    status: $.status
+  validate:
+    - contains: id
+
+
+
+
+

+ 14 - 0
test_case/jiangwei_demo/test_003_masjy.yaml

@@ -0,0 +1,14 @@
+
+-
+  name: 创建标签接口
+  request:
+    method: post
+    url: /tags/create?access_token=${read_yaml(token)}
+    json: {"tag":{"name":"重庆${get_random_number(1111,30000)}"}}
+  extract:
+    tag_id: $.tag.id
+  validate:
+    - contains: id
+
+
+

+ 11 - 0
test_case/jiangwei_demo/test_004_masjy.yaml

@@ -0,0 +1,11 @@
+-
+  name: 编辑标签接口
+  request:
+    method: post
+    url: /tags/update?access_token=${read_yaml(token)}
+    json: {"tag":{"id": "${read_yaml(tag_id)}","name":"重庆${get_random_number(1111,30000)}"}}
+  validate:
+    - contains: ok
+
+
+

+ 12 - 0
test_case/jiangwei_demo/test_005_masjy.yaml

@@ -0,0 +1,12 @@
+
+-
+  name: 删除标签接口
+  request:
+    method: post
+    url: /tags/delete?access_token=${read_yaml(token)}
+    json: {"tag":{"id": "${read_yaml(tag_id)}"}}
+  validate:
+    - equals: {'errmsg': 'ok'}
+
+
+

+ 0 - 0
test_case/qccq/__init__.py


+ 19 - 0
test_case/qccq/test_001_登录接口.yaml

@@ -0,0 +1,19 @@
+
+-
+  name: 登录成功
+  request:
+    method: post
+    url: /service-sysmgr/LoginController/login
+    json:
+      captcha: 'youthcq'
+      captchaKey: 'wwohetlyfcuswjcxeyglkpxl'
+      password: "5856464E5731466E547A4D794D6C2B42334973312B784D3561584E4264726F487532746F37664C6F70326F47752B6F585043426543704356777A59717065774A6F423439385659426F6668716D496C75484A344F54416764676668596F6478554C6365643255793742736B56714B6271644858777675724F6D3959794667356D455071796C7858776D586D72672B344F4A57654249677779546631612B6E4B724E334C6B4B695A336A574D3D"
+      scope: "WEB"
+      username: "17723565637"
+  extract:
+    token: '"token":"(.*?)"'
+  validate:
+    - contains:  true
+
+
+

+ 28 - 0
test_case/qccq/test_002_接入管理_分页条件查询.yaml

@@ -0,0 +1,28 @@
+
+-
+  name: $ddt{name}
+  request:
+    method: post
+    url: /service-sysmgr/auth/AccessController/pageSearch
+    json:
+      pageNo: $ddt{pageNo}
+      pageSize: $ddt{pageSize}
+      query:
+        systemName: $ddt{systemName}
+        state: $ddt{state}
+    headers:
+      Token: ${read_yaml(token)}
+  parameterize:
+    - [ 'name','pageNo','pageSize','asser_str','systemName','state']
+    - [ '分页查询1页10条数据,名称是”测试“','1','10',data,'测试',1]
+    - [ '分页查询2页10条数据,名称是”校外教育','2','10',data ,'校外教育',1]
+    - [ '分页查询1页100条数据','1','100',data, '自有应用',1]
+    - [ '分页查询1页50条数据','1','50','state': 1 ,'',1]
+    - [ '查询状态失效的','1','50','state': 0,'',0]
+  extract:
+    quarterId: '"quarterId":"(.*?)"'
+  validate:
+    - contains: $ddt{asser_str}
+
+
+

+ 38 - 0
test_case/qccq/test_002_接入管理_新增.yaml

@@ -0,0 +1,38 @@
+
+-
+  name: $ddt{name}
+  request:
+    method: post
+    url: /service-sysmgr/auth/AccessController/create
+    json:
+      appCode: "测试${get_random_number(1,1000)}"
+      systemName: "测试${get_random_number(1,9000)}"
+      sponsor: 1675680915889610752
+      logoUrl: "20230922/dbc9d08ffc8f43609e9e8192e2ebe48c.jpg"
+      appType: 2
+      appName: "APP名称name${get_random_number(1,1000)}"
+      appUrl: "APP地址${get_random_number(1,9000)}"
+      sort: 16
+      publicKey: null
+      privateKey: null
+      mustHex: 0
+      mustAuth: 0
+      state: 1
+      notes: "测试"
+      appId: "1705048780670922752"
+    headers:
+      Token: ${read_yaml(token)}
+#  parameterize:
+#    - [ 'name','pageNo','pageSize','asser_str','systemName','state']
+#    - [ '分页查询1页10条数据,名称是”测试“','1','10',data,'测试',1]
+#    - [ '分页查询2页10条数据,名称是”校外教育','2','10',data ,'校外教育',1]
+#    - [ '分页查询1页100条数据','1','100',data, '自有应用',1]
+#    - [ '分页查询1页50条数据','1','50','state': 1 ,'',1]
+#    - [ '查询状态失效的','1','50','state': 0,'',0]
+  extract:
+    quarterId: '"quarterId":"(.*?)"'
+  validate:
+    - contains: data
+
+
+

+ 31 - 0
test_case/qccq/test_allAPI2.py

@@ -0,0 +1,31 @@
+import json
+
+from pathlib import Path
+
+import allure
+import pytest
+
+from common.parameterize import ddt, read_testcase
+from common.request_util import RequestUtil
+
+path = Path(__file__).parent.glob("**/*.yaml")
+
+
+def creat_case(yaml_path):
+    @pytest.mark.parametrize("arg_names", read_testcase(rf"{yaml_path}"))
+    def test_fun(self, arg_names):
+        allure.dynamic.title(arg_names["name"])
+        RequestUtil("base_qccq_tyy").standard_yaml(arg_names)
+
+    return test_fun
+
+
+@allure.epic("青春重庆")
+@allure.feature("用户管理模块")
+class TestAPI:
+    pass
+
+
+for yaml_path in path:
+    yaml_name = yaml_path.name[:-5]
+    setattr(TestAPI, yaml_name, creat_case(yaml_path))

+ 31 - 0
test_case/test_allAPI.py

@@ -0,0 +1,31 @@
+import json
+
+from pathlib import Path
+
+import allure
+import pytest
+
+from common.parameterize import ddt, read_testcase
+from common.request_util import RequestUtil
+
+path = Path(__file__).parent.glob("**/*.yaml")
+
+
+def creat_case(yaml_path):
+    @pytest.mark.parametrize("arg_names", read_testcase(rf"{yaml_path}"))
+    def test_fun(self, arg_names):
+        allure.dynamic.title(arg_names["name"])
+        RequestUtil("base_tzjs_url").standard_yaml(arg_names)
+
+    return test_fun
+
+
+@allure.epic("中国移动营销管理系统")
+@allure.feature("用户管理模块")
+class TestAPI:
+    pass
+
+
+for yaml_path in path:
+    yaml_name = yaml_path.name[:-5]
+    setattr(TestAPI, yaml_name, creat_case(yaml_path))