Beispiel #1
0
def register(setup_data, baserequest, url, db_info):
    # 注册用户
    r = Member.register(baserequest, url, setup_data['data'])
    print(r.text)
    yield
    # 删除注册用户
    MySqlOp.delete_user(db_info, setup_data['data']['mobilephone'])
Beispiel #2
0
def test_register_pass(pass_data, baserequest, url, db_info):
    '''
    注册成功
    :param pass_data: 注册成功数据
    :param baserequest:
    :param url:
    :return:
    '''
    # 初始化环境,避免环境中已有本次测试用到的数据
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])

    print(pass_data)
    # 下发请求
    r = Member.register(baserequest, url, pass_data['data'])
    print(r.text)
    # 断言
    # assert r.json()['code'] == pass_data['expect']['code']
    # assert r.json()['status'] == pass_data['expect']['status']
    # assert r.json()['msg'] == pass_data['expect']['msg']
    # 重复的代码,出现次数多的代码,可以封装为方法,简化调用
    Check.equla(r.json(), pass_data['expect'], 'code,status,msg')
    # 检查用户在系统中注册成功(1、该用户可以登录成功)
    # 2.检查数据库中查有没有这个用户
    # 3. 查询类接口,比如list去查找
    r = Member.list(baserequest, url)
    assert str(pass_data['data']['mobilephone']) in r.text
    # 清理环境;删除用户mobilephone
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])
Beispiel #3
0
def test_register_pass(baserequest, url, pass_data, db_info):
    '''
    注册成功的脚本
    :param baserequest:
    :param url:
    :param pass_data:
    :return:
    '''

    # 初始化环境,避免环境中已有本次测试用到的数据
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])

    print(pass_data)
    r = Member.register(baserequest, url, pass_data['data'])
    print(r.text)

    #检查结果与预期结果一致
    # assert r.json()['code']==pass_data['expect']['code']
    # assert r.json()['status']==pass_data['expect']['status']
    # assert r.json()['msg']==pass_data['expect']['msg']
    # 重复代码,出现次数多的代码,可以封装成方法,简化调用
    Check.equal(r.json(), pass_data['expect'], 'code,status,msg')

    #检查用户在系统中注册成功(1、注册的用户登录;2、数据库中查有没有这个用户;3、查询类的接口,比如list接口返回值能查到这个用户)
    r = Member.list(baserequest, url)
    assert pass_data['data']['mobilephone'] in r.text

    #清理环境:删除用户(1、接口删除用户;2、数据库中删除用户)
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])
def test_register_pass(pass_data, baserequest, url, db_info):
    '''
    注册成功
    :return:
    '''
    # 初始化环境:避免环境中已有本次测试用到的数据
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])
    # 下发请求
    r = Member.register(baserequest, url, pass_data['data'])
    # 检查接口的返回结果与预期结果一致
    assert r.json()['code'] == pass_data['expect']['code']
    assert r.json()['status'] == pass_data['expect']['status']
    assert r.json()['msg'] == pass_data['expect']['msg']
    # 检查用户在系统中注册成功(1、该用户可以登录成功;
    # 2、数据库中查有没有这个用户;3、查询类的接口,比如list接口返回值能查到这个用户)
    r = Member.list(baserequest, url)
    assert pass_data['data']['mobilephone'] in r.text
    # 清理环境:删除用户(1、接口删除用户 2、数据库中删除用户)
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])

    # 原则1:测试环境,在执行脚本前是什么状态,执行完脚本要恢复到之前的状态。(清理环境)
    # 原则2:脚本执行依赖的环境,要在脚本中自己构造。比如
    # 审核项目接口测试时依赖已有的项目,需要先调用添加项目的接口准备测试环境。
    # 脚本的健壮性、稳定性比较高。


# def test_register_repeat(repeat_data, baserequest, url, db_info):
#     # 重复注册测试逻辑
#     # 环境准备:下发注册请求
#     # 测试步骤:下发注册请求,检查结果,报错重复注册
#     # 恢复环境:删除用户
#     pass
Beispiel #5
0
def test_login(login_data, baserequest, url):
    # 初始化环境:避免环境中已有本次测试用到的数据
    MySqlOp.delete_user(db_info, setup_data['data']['mobilephone'])
    # 注册用户
    Member.register(baserequest, url, setup_data['regdata'])
    print("注册数据", login_data['regdata'])
    # 登录
    print("登录数据", login_data['logindata'])
Beispiel #6
0
def register(setup_data, baserequest, url, db_info):
    # 初始化环境:避免环境中已有本次测试用到的数据
    MySqlOp.delete_user(db_info, setup_data['data']['mobilephone'])
    # 注册用户
    r = Member.register(baserequest, url, setup_data['data'])
    yield
    # 清理环境:删除用户(1、接口删除用户 2、数据库中删除用户)
    MySqlOp.delete_user(db_info, setup_data['data']['mobilephone'])
Beispiel #7
0
def register(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'])
Beispiel #8
0
def register_login(baserequest, url, recharge_data, db_info):
    # 初始化环境
    MySqlOp.delete_user(recharge_data['regdata']['mobilephone'], db_info)
    # 注册用户
    Member.register(baserequest, url, recharge_data['regdata'])
    # 用户登录
    Member.login(baserequest, url, recharge_data['logindata'])
    yield
    MySqlOp.delete_user(recharge_data['regdata']['mobilephone'], db_info)
Beispiel #9
0
def register(baserequest, url, setup_data, db_info):
    # 初始化环境:避免环境中已有本次测试的数据
    MySqlOp.delete_user(setup_data['data']['mobilephone'], db_info)
    # 注册用户
    r = Member.register(baserequest, url, setup_data)
    print(r.text)
    yield  # yeild 之前是前置,之后是后置
    # 清理环境:删除用户(1.接口删除数据 2.数据库删除用户)
    MySqlOp.delete_user(setup_data['data']['mobilephone'], db_info)
Beispiel #10
0
def test_recharge(recharge_data, baserequest, url, db_info):
    # 注册用户
    MySqlOp.delete_user(db_info, recharge_data['regdata']['mobilephone'])
    Member.register(baserequest, url, recharge_data['regdata'])
    # 登录用户
    Member.login(baserequest, url, recharge_data['logindata'])
    # 充值
    r = Member.recharge(baserequest, url, recharge_data['rechdata'])
    # 校验结果
    Check.equal(r.json(), recharge_data['expect'], 'code,status,msg')
Beispiel #11
0
def test_register_repeat(baserequest, url, sucess_data, db_info):

    # 环境准备
    MySqlOp.delete_user(sucess_data['data']['mobilephone'], db_info)
    Member.register(baserequest, url, sucess_data['data'])
    # 测试步骤:测试下发注册请求(检查结果,报错重复注册)
    r1 = Member.register(baserequest, url, sucess_data['data'])
    print(r1.text)
    # 恢复环境
    MySqlOp.delete_user(sucess_data['data']['mobilephone'], db_info)
Beispiel #12
0
def test_login_01(baserequest, url, login, db_info):
    # 初始化环境
    MySqlOp.delete_user(login['regdata']['mobilephone'], db_info)
    # 注册用户
    r = Member.register(baserequest, url, login['regdata'])
    print(r.text)
    r1 = Member.login(baserequest, url, login['logindata'])
    print(r1.text)
    Check.equal(r1.json(), login['expect'], 'code,status,msg')

    # 清理环境
    MySqlOp.delete_user(login['logindata']['mobilephone'], db_info)
Beispiel #13
0
def register(setup_data, baserequest, url, db_info):
    # 注册用户
    MySqlOp.delete_user(db_info, setup_data['data']['mobilephone'])
    r = Member.register(baserequest, url, setup_data['data'])
    # assert r.json()['code'] == setup_data['expect']['code']
    # assert r.json()['status'] == setup_data['expect']['status']
    # assert r.json()['msg'] == setup_data['expect']['msg']
    Check.equal(r.json(), setup_data['expect'], 'code,status,msg')

    yield  # 之前是前置,之后是后置
    # 删除注册用户
    MySqlOp.delete_user(db_info, setup_data['data']['mobilephone'])
Beispiel #14
0
def test_login(login_data, baserequest, url, db_info):
    # 初始化环境:避免环境中已有本次测试用到的数据
    MySqlOp.delete_user(db_info, login_data['regdata']['mobilephone'])
    # 注册用户
    print("注册数据:", login_data['regdata'])
    r = Member.register(baserequest, url, login_data['regdata'])
    # 登录
    print("登录数据:", login_data['logindata'])
    # 检查结果
    r = Member.login(baserequest, url, login_data['logindata'])
    assert r.json()['code'] == login_data['expect']['code']
    assert r.json()['status'] == login_data['expect']['status']
    assert r.json()['msg'] == login_data['expect']['msg']
    # 删除注册用户
    MySqlOp.delete_user(db_info, login_data['regdata']['mobilephone'])
Beispiel #15
0
def test_login(login_data, db_info, baserequest, url):
    #注册用户
    print("注册数据", login_data['regdata'])
    # 初始化环境:避免环境中已有本次测试用到的数据
    # MySqlOp.delete_user(db_info, login_data['data']['mobilephone'])
    r = Member.register(baserequest, url, login_data['regdata'])
    #登录
    print("登录数据", login_data['logindata'])
    r = Member.login(baserequest, url, login_data['logindata'])
    #检查结果
    # assert r.json()['code'] == login_data['expect']['code']
    # assert r.json()['status'] == login_data['expect']['status']
    # assert r.json()['msg'] == login_data['expect']['msg']
    Check.equal(r.json(), login_data['expect'], 'code,status,msg')
    #删除注册用户
    MySqlOp.delete_user(db_info, login_data['regdata']['mobilephone'])
Beispiel #16
0
def test_login(login_data, baserequest, url, db_info ):
    # 注册用户  初始化环境脚本里自己创建环境数据
    MySqlOp.delete_user(db_info, login_data['regdata']['mobilephone'])
    print("注册数据:", login_data['regdata'])

    Member.register(baserequest, url, login_data['regdata'])
    #登录
    print("登录数据:", login_data['logindata'])
    r= Member.login(baserequest, url, login_data['logindata'])
    # 检查结果
    assert r.json()['code'] == login_data['expect']['code']
    assert r.json()['status'] == login_data['expect']['status']
    assert r.json()['msg'] == login_data['expect']['msg']

   # 删除注册用户  后置清理初始化环境
    MySqlOp.delete_user(db_info, login_data['regdata']['mobilephone'])
Beispiel #17
0
def test_login(login_data,baserequest,url,db_info):
    # 注册用户
    MySqlOp.delete_user(db_info,login_data['regdata']['mobilephone'])
    Member.register(baserequest,url,login_data['regdata'])

    # 登录
    r = Member.login(baserequest,url,login_data['logindata'])

    # 检查结果
    # assert r.json()['code'] == login_data['expect']['code']
    # assert r.json()['status'] == login_data['expect']['status']
    # assert r.json()['msg'] == login_data['expect']['msg']
    Check.equal(r.json(),login_data['expect'],'code,status,msg')

    # 删除注册用户
    MySqlOp.delete_user(db_info,login_data['regdata']['mobilephone'])
Beispiel #18
0
def test_register_pass(sucess_data, baserequest, url, db_info):
    '''
     注册成功
    :return:
    '''
    # 初始化
    MySqlOp.delete_user(sucess_data['data']['mobilephone'], db_info)
    # 下发请求
    r = Member.register(baserequest, url, sucess_data['data'])
    print(r.text)
    # 检查接口返回与预期结果一致
    assert r.json()['msg'] == sucess_data['expect']['msg']
    assert r.json()['code'] == sucess_data['expect']['code']
    assert r.json()['status'] == sucess_data['expect']['status']
    # 检查用户在系统中注册成功
    r1 = Member.list(baserequest, url)
    assert sucess_data['data']['mobilephone'] in r1.text
Beispiel #19
0
def test_login(baserequest, url, db_info, login_data):
    MySqlOp.delete_user(db_info, login_data['regdata']['mobilephone'])
    #注册用户
    print("注册数据:", login_data['regdata'])
    r = Member.register(baserequest, url, login_data['regdata'])
    #登录
    print("登录数据:", login_data['logindata'])
    r = Member.login(baserequest, url, login_data['logindata'])

    #检查结果
    # assert r.json()['code'] == login_data['expect']['code']
    # assert r.json()['status'] == login_data['expect']['status']
    # assert r.json()['msg'] == login_data['expect']['msg']
    # 重复代码,出现次数多的代码,可以封装成方法,简化调用
    Check.equal(r.json(), login_data['expect'], 'code,status,msg')

    #删除注册用户
    MySqlOp.delete_user(db_info, login_data['regdata']['mobilephone'])
def test_register_pass(pass_data, baserequest, url, db_info):
    '''
    注册成功
    :return:
    '''
    # 初始化环境:避免环境中已有本次测试用到的数据
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])
    # 下发请求
    r = Member.register(baserequest, url, pass_data['data'])
    # 检查接口的返回结果与预期结果一致
    assert r.json()['code'] == pass_data['expect']['code']
    assert r.json()['status'] == pass_data['expect']['status']
    assert r.json()['msg'] == pass_data['expect']['msg']
    # 检查用户在系统中注册成功(1、该用户可以登录成功;
    # 2、数据库中查有没有这个用户;3、查询类的接口,比如list接口返回值能查到这个用户)
    r = Member.list(baserequest, url)
    assert pass_data['data']['mobilephone'] in r.text
    # 清理环境:删除用户(1、接口删除用户 2、数据库中删除用户)
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])
Beispiel #21
0
def test_register_pass(pass_data, baserequest, url, db_info):
    '''
    注册成功
    :return:
    '''
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])
    print(pass_data)
    # 下发请求
    r = Member.register(baserequest, url, pass_data['data'])
    # 检查接口的返回结果与预期结果一致
    # assert r.json()['code'] == pass_data['expect']['code']
    # assert r.json()['status'] == pass_data['expect']['status']
    # assert r.json()['msg'] == pass_data['expect']['msg']
    Check.equal(r.json(), pass_data['expect'], 'code,status,msg')

    # 检查用户在系统中注册成功(1、该用户可以登录成功;
    # 2、数据库中查有没有这个用户;3、list 接口返回值能查到这个用户)
    r = Member.list(baserequest, url)
    assert pass_data['data']['mobilephone'] in r.text
    # 清理环境:删除用户(1、接口删除用户;2、数据库删除用户)
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])

    # 自动化测试原则
    # 1、测试环境:再执行脚本前是什么状态,执行完脚本要恢复到之前的状态
    # 2、脚本执行依赖的环境,要在脚本中自己构造。比如:
    # 审核项目接口测试时依赖已有的项目,需要先调用添加项目的接口准备测试环境。
    # 脚本的健壮性、稳定性比较高。

# @pytest.fixture(params=DataRead.read_yaml("test_data/register_repeat.yaml"))
# def repeat_data(request):
#     return request.param

# def test_register_repeat(repeat_data, baserequest,url,db_info):
#     # 重复注册测试逻辑
#     print(repeat_data)
#     # 环境准备:下发注册请求
#     r = Member.register(baserequest, url, repeat_data['data'])
#     # 测试步骤:下发注册请求(检查结果,报错重复注册)
#     # assert r.json()['code'] == repeat_data['expect']['code']
#     # assert r.json()['status'] == repeat_data['expect']['status']
#     # assert r.json()['msg'] == repeat_data['expect']['msg']
#     # 恢复环境:删除用户
#     # MySqlOp.delete_user(db_info, repeat_data['data']['mobilephone'])
Beispiel #22
0
def test_register_pass(baserequest, pass_data, url, db_info):
    '''
    注册成功
    :return:
    '''
    # 初始化环境:避免环境中已有本次测试用到的数据
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])
    # 下发请求
    r = Member.register(baserequest, url, pass_data['data'])
    print(r.text)
    # 检查接口的返回值与预期结果一致
    # assert r.json()['code'] == pass_data['expect']['code']
    # assert r.json()['status'] == pass_data['expect']['status']
    # assert r.json()['msg'] == pass_data['expect']['msg']
    Check.equal(r.json(), pass_data['expect'], 'code,status,msg')
    # 检查用户在系统中注册成功(1、该用户可以登录成功;
    # 2、数据库中查有没有这个用户;3、list接口返回值能查到这个用户)
    r = Member.list(baserequest, url)
    assert pass_data['data']['mobilephone'] in r.text
    # r = Member.register(baserequest,url,pass_data['data'])
    # assert r.json()['code'] == "20110"
    # 清理环境:删除用户(1.接口删除用户 2.数据库中删除用户)
    MySqlOp.delete_user(db_info, pass_data['data']['mobilephone'])
Beispiel #23
0
def test_register_pass(pass_data,baserequest,url,db_info):
    '''
    注册成功
    :return:
    '''
    # 初始化环境:避免环境中已有本次测试用到的数据
    MySqlOp.delete_user(db_info,pass_data['data']['mobilephone'])
    # 下发请求
    print(pass_data)
    r = Member.register(baserequest,url,pass_data['data'])
    print(r.text)
    # 检查接口的返回结果与预期结果一致
    # assert r.json()['code'] == pass_data['expect']['code']
    # assert r.json()['status'] == pass_data['expect']['status']
    # assert r.json()['msg'] == pass_data['expect']['msg']
    Check.equal(r.json(),pass_data['expect'],'code,status,msg')

    # 检查用户在系统中注册成功(1.该用户是否可以登陆成功;2.数据库中查有没有这个用户
    #                       3.查询类的接口,比如list接口返回值能否查到这个用户)
    r = Member.list(baserequest,url)
    assert pass_data['data']['mobilephone'] in r.text
    # 清理环境:删除用户(1.接口删除用户;2.数据库中删除用户)
    MySqlOp.delete_user(db_info,pass_data['data']['mobilephone'])