コード例 #1
0
def test_register_01(test_info):
    """注册用例。"""
    actual_url = test_info['url']
    actual_method = test_info['method']
    actual_json = test_info['json']
    actual_headers = test_info['headers']
    expected = test_info['expected']

    # 读取 test_info['json']
    # 如果存在#new_phone#
    if '#new_phone#' in actual_json:
        # 生成手机号码 generate_new_phone
        # 13789456789 替换 #new_phone#
        phone = generate_new_phone()
        actual_json = actual_json.replace('#new_phone#', phone)

    resp = requests.request(method=actual_method,
                            url=yaml_config['host'] + actual_url,
                            headers=eval(actual_headers),
                            json=eval(actual_json))
    print(actual_json)
    resp_body = resp.json()

    try:
        assert resp_body['code'] == expected

    except AssertionError as e:
        logger.error("用例失败:{}".format(e))
        # 一定要记得抛出
        raise e
コード例 #2
0
def test_login(info):
    request_data = info['data']
    if '*phone*' in request_data:
        new_phone = generate_new_phone()
        request_data = request_data.replace('*phone*', new_phone)

    if '#phone#' in request_data:
        phone = user_config['investor_user']['phone']
        request_data = request_data.replace('#phone#', phone)

    if '#pwd#' in request_data:
        pwd = user_config['investor_user']['pwd']
        request_data = request_data.replace('#pwd#', pwd)

    print(request_data)

    resp = requests.request(method=info['method'],
                            url=yaml_config['host'] + info['url'],
                            headers=eval(info['headers']),
                            json=eval(request_data))

    try:
        assert resp.json()['msg'] == info['expected']
    except AssertionError as e:
        logger.error(e)
        logger.info("测试数据:{}".format(request_data))
        raise e
コード例 #3
0
def test_register_01(test_info):
    url = test_info['url']
    method = test_info['method']
    headers = test_info['headers']
    json = test_info['json']
    expected = test_info['expected']

    if "#new_phone#" in json:
        phone = generate_new_phone()
        json = json.replace('#new_phone#', phone)

    # 访问接口
    resp = requests.request(method=method,
                            url=yaml_config["host"] + url,
                            headers=eval(headers),
                            json=eval(json))
    # 获取响应体json
    resp_body = resp.json()
    # 断言
    try:
        assert resp_body['code'] == expected
    except AssertionError as e:
        logger.error("用例失败{}".format(e))
        # 抛出异常
        raise e
コード例 #4
0
def test_login (test_info):
    actual_url = test_info['url']
    actual_method = test_info['method']
    actual_json = test_info['json']
    actual_headers = test_info['headers']
    expected = test_info['expected']

    if '*phone*' in actual_json:
        mobile_phone =generate_new_phone()
        actual_json = actual_json.replace('*phone*',mobile_phone)
    if '#phone#' in actual_json:
        mobile_phone =user_config['investor_user']['phone']
        actual_json = actual_json.replace('#phone#',mobile_phone)
    if '#pwd#' in actual_json:
        pwd =user_config['investor_user']['pwd']
        actual_json = actual_json.replace('#pwd#',pwd)
    print(actual_json)
    res = requests.request(method=actual_method,
                           url=yaml_config['host'] + actual_url,
                           headers=eval(actual_headers),
                           json=eval(actual_json))
    res_body = res.json()

    try:
        assert res_body['code'] == expected
    except AssertionError as e:
        logger.error("用例失败:{}".format(e))
        raise e
    finally:
        excel = ExcelHandler(excel_file)
        excel.write('login',str(res_body),row=int(test_info['case_id']+1),column=9)
        if res_body['code']== expected:
            excel.write('login',True,row=int(test_info['case_id']+1),column=8)
        else:
            excel.write('login',False,row=int(test_info['case_id']+1),column=8)
コード例 #5
0
def test_register_01(test_info):
    """注册用例"""
    # url = 'http://api.lemonban.com/futureloan/member/register'
    # method = 'POST'
    # json = {"mobile_phone": "", "pwd": ""}
    # headers = {"X-Lemonban-Media-Type": "lemonban.v2"}
    # expected = 2

    method = test_info['method']
    url = test_info['url']
    json = test_info['json']
    headers = test_info['headers']
    expected = test_info['expected']

    # 读取 test_info['json']
    # 如果存在#new_phone#
    if '#new_phone#' in json:
        # 生成手机号码 generate_new_phone
        # 15195989875 替换 #new_phone#
        phone = generate_new_phone()
        json = json.replace('#new_phone#', phone)

    if '#exist_phone#' in json:
        phone = generate_new_phone()
        json = json.replace('#exist_phone#', phone)

    resp = requests.request(method=method,
                            url=yaml_config['host'] + url,
                            headers=eval(headers),
                            json=eval(json))
    print(json)

    # 获取响应体:json
    resp_body = resp.json()

    # 断言和日志
    try:
        assert resp_body['code'] == expected
    except AssertionError as e:
        logger.error("用例失败:{}".format(e))
        # 一定要记得抛出
        raise e
コード例 #6
0
def test_register_01(test_info):
    # actual_url = 'http://api.lemonban.com/futureloan/member/register'
    # actual_method = 'POST'
    # actual_json = {"mobile_phone":"","pwd":""}
    # actual_headers = {"X-Lemonban-Media-Type":"lemonban.v2"}
    # expected = 2
    # 元组要控制索引
    # actual_url = test_info[3]
    # actual_method = test_info[6]
    # actual_json = test_info[4]
    # actual_headers = test_info[5]
    # expected = test_info[7]
    # 字典取值
    actual_url = test_info['url']
    actual_method = test_info['method']
    actual_json = test_info['json']
    actual_headers = test_info['headers']
    expected = test_info['expected']
    # 读取 test_info['json'],
    # 如果存在 # new_phone,
    if '#new_phone#' in actual_json:
        # 生成手机号码 13789456789 generate_new_phone
        mobile_phone = generate_new_phone()
        # 替换为new_phone
        actual_json = actual_json.replace('#new_phone#', mobile_phone)
    # 传入都是字符串
    res = requests.request(method=actual_method,
                           url=yaml_config['host'] + actual_url,
                           headers=eval(actual_headers),
                           json=eval(actual_json))
    res_body = res.json()
    print(res_body)
    try:
        assert res_body['code'] == expected
    except AssertionError as e:
        logger.error("用例失败:{}".format(e))
        raise e
    finally:
        excel = ExcelHandler(excel_file)
        excel.write('register',
                    str(res_body),
                    row=int(test_info['case_id']) + 1,
                    column=9)
        if res_body['code'] == expected:
            excel.write('register',
                        'True',
                        row=int(test_info['case_id']) + 1,
                        column=8)
        else:
            excel.write('register',
                        'False',
                        row=int(test_info['case_id']) + 1,
                        column=8)