示例#1
0
'''
充值测试
'''
import pytest

from Zonghe.baw import Member
from Zonghe.caw import DataRead, MysqlOP, Check


# 获取测试数据
@pytest.fixture(params=DataRead.read_yaml("test_data/recharge.yaml"))
def recharge_data(request):
    return request.param

def test_recharge(recharge_data,baserequest,url,db_info):
    # 初始换环境
    MysqlOP.delete_user(db_info,recharge_data['register']['mobilephone'])
    # 注册用户
    Member.register(baserequest,url,recharge_data['register'])
    # 充值
    r = Member.recharge(baserequest,url,recharge_data['data'])
    # 断言验证
    Check.equal(r.json(),recharge_data['expect'],'code,msg,status')
    # 恢复初始化环境
    MysqlOP.delete_user(db_info, recharge_data['register']['mobilephone'])
示例#2
0
def url():
    return DataRead.readini("Zonghe\data_env\env.ini", 'url')
示例#3
0
import pytest

from Zonghe.baw import Member
from Zonghe.caw import DataRead, MysqlOP, Check


@pytest.fixture(params=DataRead.read_yaml(r"test_data/login.yaml"))
def login_data(request):
    return request.param


def test_login(login_data,baserequest,url,db_info):
    # 创建初始环境
    MysqlOP.delete_user(db_info, login_data['register']['mobilephone'])
    # 注册用户
    r = Member.register(baserequest,url,login_data['register'])
    # 登录
    q = Member.login(baserequest,url,login_data['data'])
    # 检查结果
    '''
    assert q.json()['code'] == login_data['expect']['code']
    assert q.json()['status'] == login_data['expect']['status']
    assert q.json()['msg'] == login_data['expect']['msg']
    '''
    Check.equal(q.json(),login_data['expect'],'code,status,msg')
    # 恢复环境
    MysqlOP.delete_user(db_info,login_data['register']['mobilephone'])
示例#4
0
import pytest

from Zonghe.baw import Member
from Zonghe.caw import DataRead, MysqlOP


# 登录前置(注册)数据
@pytest.fixture(params=DataRead.read_yaml(r"test_data/login_setup.yaml"))
def setup_data(request):
    return request.param


# 登录数据
@pytest.fixture(params=DataRead.read_yaml(r"test_data/login_data.yaml"))
def login_data(request):
    return request.param


@pytest.fixture()
def regiter(setup_data, baserequest, url, db_info):
    # 初始化环境
    MysqlOP.delete_user(db_info, setup_data['data']['mobilephone'])
    # 注册用户
    r = Member.register(baserequest, url, setup_data['data'])
    yield
    # 清理环境,删除用户
    MysqlOP.delete_user(db_info, setup_data['data']['mobilephone'])


def test_login(regiter, baserequest, url, login_data):
    # 下发登录请求
示例#5
0
'''
登录的测试脚本(pytest)
'''
import pytest
from Zonghe.caw import DataRead
from Zonghe.baw import Member, DbOp
import requests
#读取yaml文件
@pytest.fixture(params=DataRead.readyaml("Zonghe/data_case/login_fail.yaml"))
def fail_data(request):
    return request.param

@pytest.fixture(params=DataRead.readyaml("Zonghe/data_case/login_pass.yaml"))
def pass_data(request):
    return request.param
#测试前置和后置
@pytest.fixture()
def register(pass_data, url, baserequests, db):
    # 注册
    phone = pass_data['casedata']['mobilephone']
    DbOp.deleteUser(db, phone)
    Member.register(url, baserequests, pass_data['casedata'])
    yield
    #删除注册用户
    DbOp.deleteUser(db, phone)

def test_login(register,pass_data, baserequests, url, db):
    print(f"测试数据为:{pass_data['casedata']}")
    print(f"预期结果为:{pass_data['expect']}")
    phone = pass_data['casedata']['mobilephone']
    r = Member.login(url, baserequests, pass_data['casedata'])
示例#6
0
'''
充值的测试脚本
'''

import pytest

from Zonghe.caw import DataRead
from Zonghe.baw import Member, DbOp


@pytest.fixture(params=DataRead.readyaml("Zonghe/data_case/recharge_data.yaml")
                )
def recharge_data(request):
    return request.param


def test_recharge(recharge_data, url, baserequests):
    print(f"测试数据为:{recharge_data['casedata']}")
    print(f"预测结果为:{recharge_data['expect']}")
    # 充值
    r = Member.recharge(url, baserequests, recharge_data['casedata'])
    # 检查充值结果
    assert r.json()['msg'] == recharge_data['expect']['msg']
    assert r.json()['code'] == recharge_data['expect']['code']
    assert r.json()['status'] == recharge_data['expect']['status']
示例#7
0
def url():
    return DataRead.readini("Zonghe/data_env/env.ini","url")
示例#8
0
import pytest

from Zonghe.baw import Member, DbOp
from Zonghe.caw import DataRead


# 登录数据
@pytest.fixture(params=DataRead.readyaml("Zonghe/data_case/login_data.yaml"))
def login_data(request):  # 固定写法
    return request.param


# 登陆前置数据
@pytest.fixture(params=DataRead.readyaml("Zonghe/data_case/login_setup.yaml"))
def setup_data(request):  # 固定写法
    return request.param


# 测试前后置
@pytest.fixture()
def register(setup_data, url, baserequests, db):
    connent = DbOp.connent(db)
    # 注册
    phone = setup_data['casedata']['mobilephone']
    DbOp.deleteUser(connent, phone)
    Member.register(url, baserequests, setup_data['casedata'])
    yield
    # 删除
    DbOp.deleteUser(connent, phone)
    DbOp.disconnect(connent)
示例#9
0
def url():
    return DataRead.read_ini(r"test_env\env.ini", "url")
示例#10
0
def db_info():
    # ini读出来是字符串,但是db_info是字典,使用eval解析为原文本格式
    return eval(DataRead.read_ini(r"test_env\env.ini", "db_info"))
示例#11
0
'''
测试注册的脚本
'''

import pytest

from Zonghe.baw import Member
from Zonghe.caw import DataRead, MysqlOP


@pytest.fixture(params=DataRead.read_yaml(r"test_data/register_fail.yaml"))
def fail_data(request):
    return request.param


'''
@pytest.fixture(params=DataRead.read_yaml(r"test_data/login_data.yaml"))
def login_data(request):
    return request.param
'''


def test_register_fail(fail_data, baserequest, url):
    '''
    注册失败的脚本
    :return:
    '''
    # 下发请求
    # 校验结果
    # 打印数据 print(fail_data)
示例#12
0
def db():
    # 从ini中读取出来是字符串,将字符串转成字典,使用eval函数
    return eval(DataRead.readini('Zonghe/data_env/env.ini', 'db'))
示例#13
0
def url():
    return DataRead.readini('Zonghe/data_env/env.ini', 'url')
示例#14
0
def db():
    # 将从ini中读取的字符串转为字典,使用eval函数
    return eval(DataRead.readini("Zonghe\data_env\env.ini", 'db'))
示例#15
0
def db():
    # 从ini中读取出来的字符串,将字符串转成字典,使用eval函数
    return eval(DataRead.readini("Zonghe/data_env/env.ini","db"))
示例#16
0
'''
注册的测试脚本(pytest)
'''

import pytest
from Zonghe.caw import DataRead
from Zonghe.baw import Member, DbOp

# 测试前置:获取测试数据,为列表,通过readyaml读取而来
from Zonghe.test_script.conftest import db


@pytest.fixture(params=DataRead.readyaml("Zonghe/data_case/register_fail.yaml")
                )
def fail_data(request):  # 固定写法
    return request.param


@pytest.fixture(params=DataRead.readyaml("Zonghe/data_case/register_pass.yaml")
                )
def pass_data(request):  # 固定写法
    return request.param


@pytest.fixture(
    params=DataRead.readyaml("Zonghe/data_case/register_repet.yaml"))
def repet_data(request):  # 固定写法
    return request.param


# 注册失败
示例#17
0

# 数据库操作
@pytest.fixture()
def register(db):
    # 连接
    global connent
    connent = DbOp.connent(db)
    yield
    # 断开
    DbOp.disconnect(connent)


# 注册成功数据(绝对)
@pytest.fixture(
    params=DataRead.readyaml("Zonghe\data_case\login_register_pass.yaml"))
def ng_data(request):  # 固定写法
    return request.param


# 登录失败数据
@pytest.fixture(
    params=DataRead.readyaml("Zonghe/data_case/login_fail_none.yaml"))
def fail_none_data(request):  # 固定写法
    return request.param


# 登录成功数据
@pytest.fixture(params=DataRead.readyaml("Zonghe/data_case/login_pass.yaml"))
def pass_data(request):  # 固定写法
    return request.param