八十九 pytest框架

目录


image.png

代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
韦奇_very
test_seer_app_index.py
'''

import os
import pytest
from config.read_file import read_yaml
from config.case_request import case_request
from config.config import *

class TestParams:
    @pytest.mark.parametrize('case',read_yaml('../case_yaml/test_seer_app_index.yaml'))
    def test_login(self,case,tokens):
        headers ={'auth':tokens[1]}
        print(headers)
        for case_only in case:
            urls = url + case[case_only]['url'] +'?osType=android'
            parm = case_request(urls, headers,data=1)
            back = parm.case_get()
            print(back)


if __name__ == '__main__':
    os.system("pytest test_seer_app_index.py")
# test_seer_app_index.yaml

-
  num_1:
    method: 'get'
    url: '/portal/appUpdate/selectLastVersion'
    back: 0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
韦奇_very
case_request.py
各种请求的方法
'''

import requests

class case_request:
    # 定义构造方法
    def __init__(self, url,header,data):
        self.url = url
        self.data = data
        self.header = header

    def case_post(self):
        post_back = requests.post(self.url, headers=self.header, data=self.data)
        return post_back.content

    def case_get(self):
        post_back = requests.get(self.url, headers=self.header)
        return post_back.content

#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
韦奇_very
config.py
配置文件
'''
url = 'https://dev.seth.com'
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
encryption.py
各种加密方法
'''
import hashlib
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import AES


def md55(message):
    md5 = hashlib.md5()
    b= message.encode(encoding='utf-8')
    md5.update(b)
    str_mde5 = md5.hexdigest()
    return str_mde5

def res_seer():
    # 公钥
    public_key = '''-----BEGIN PUBLIC KEY-----
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxH7CZHpAgGgGKB/qfaauM2XdX26Wy6hPZBY5J3RRVlpxCbbXQvnrWfDmxIFZ8ypbPYeaRSwd+e5JefYe/ujq5AAMZyjmQIDAQAB
    -----END PUBLIC KEY-----'''
    aes_key = "1111111111111111"
    cipher = Cipher_pkcs1_v1_5.new(RSA.importKey(public_key))
    cipher_text = base64.b64encode(cipher.encrypt(aes_key.encode())).decode()
    return cipher_text

def aes_seer(data_text):
    aes_key = "1111111111111111"
    data_texts = str(data_text) + (16 - len(str(data_text)) % 16) * chr(16 - len(str(data_text)) % 16)
    # 字符串补位
    cipher = AES.new(aes_key.encode('utf8'), AES.MODE_CBC, aes_key.encode('utf8'))
    encryptedbytes = cipher.encrypt(str(data_texts).encode('utf8'))
    # 加密后得到的是bytes类型的数据
    encodestrs = base64.b64encode(encryptedbytes)
    # 使用Base64进行编码,返回byte字符串
    enctext = encodestrs.decode('utf8')
    return enctext


# -*- coding: utf-8 -*-
'''
read_file.py
读取文件
'''
import yaml

def read_yaml(files):
    with open(files, 'r', encoding='utf-8') as f:
        result = yaml.load(f.read(), Loader=yaml.FullLoader)
    return result



#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
conftest.py
前置后置方法
'''
import pytest
import requests,json
from config.encryption import md55,aes_seer,res_seer
# from pytest_yaml_yoyo import  my_builtins

#设置公共的login方法   便于调用  调用时无需传入方法名即可调用
# @pytest.fixture(scope='module',autouse=True)

@pytest.fixture(scope='session',autouse=True)  # 多个文件调用一次
def tokens():
    # 这个是返回的token
    userid_token = ''
    return userid_token
[pytest]
addopts = -vs
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容