Пример #1
0
def generate_new_phone():
    """自动生成手机号"""
    fk = Faker(locale='zh_CN')
    while True:
        phone = fk.phone_number()
        db = DBHandler()
        phone_in_db = db.query('SELECT * FROM member WHERE mobile_phone = {}'.format(phone))
        db.close()
        if not phone_in_db:
            return phone
Пример #2
0
def test_recharge(info,login):
    """充值"""
    """先要替换"""
    if "#member_id#" in info['json']:
        info["json"] = info["json"].replace('#member_id#',str(login['id']))
    if "#wrong_member_id#" in info['json']:
        info["json"] = info["json"].replace('#wrong_member_id#', str(login['id'] + 1))

    # # token组装方式1:通过excel替换
    # if "#token#" in info['headers']:
    #     info["headers"] = info["headers"].replace("#token#",login['token'])

    # token 组装2:通过headers 添加,excel 表格里面不需要Authorization
    headers = json.loads(info["headers"])
    headers['Authorization'] = login['token']

    # 数据库访问,充值之前的余额
    db = DBHandler()
    sql = 'select leave_amount from member where id={}'.format(login['id'])
    result = db.query(sql)
    before_recharge_money =result['leave_amount']
    db.db_colse()

    data = json.loads(info['json'])
    res= requests.request(url= yaml_config['host'] + info['url'],
                     method=info['method'],
                     headers=headers,
                     json= data)
    res_body = res.json()
    print(res_body)
    try:
        assert res_body['code'] == info["expected"]
    except AssertionError as e:
        logger.error("用例失败:{}".format(e))
        raise e
    finally:
        excel = ExcelHandler(excel_file)
        excel.write('recharge',str(res_body),row=int(info['case_id']+1),column=9)
        if res_body['code'] == 0:
            db = DBHandler()
            sql = 'select leave_amount from member where id={}'.format(login['id'])
            result = db.query(sql)
            after_recharge_money = result['leave_amount']
            db.db_colse()
            money = Decimal(str(data['amount']))
            assert before_recharge_money + money == after_recharge_money
        if res_body['code'] == info["expected"]:
            excel.write('recharge',True,row=int(info['case_id']+1),column=8)
        else:
            excel.write('recharge',False,row=int(info['case_id']+1),column=8)
Пример #3
0
def generate_new_phone():
    """自动生成手机号"""
    fk = faker.Faker(locale='zh-CN')
    while True:
        phone = fk.phone_number()
        db = DBHandler()
        phone_in_db = db.query(
            'select mobile_phone from member where mobile_phone={}'.format(
                phone))
        # 查询数据库
        # 如果数据库里面有这条记录,重新生成新的手机号码,循环,不知道什么时候结束,用while
        db.db_colse()
        if not phone_in_db:
            return phone
    return phone
Пример #4
0
def generate_new_phone():
    '''自动生成手机号'''
    fk = Faker(locale='zh_CN')
    while True:
        phone = fk.phone_number()
        # 查询手机号是否在数据库中存在,如果不存在,返回新生成的手机号,如果存在,重新生成手机号
        db_phone = DBHandler(host=config_yaml['db']['host'],
                             port=config_yaml['db']['port'],
                             user=config_yaml['db']['user'],
                             password=config_yaml['db']['password'],
                             database=config_yaml['db']['database'])
        db_in_phone = db_phone.query(
            "select mobile_phone from member where mobile_phone='{}'".format(
                phone))
        # 没有查询出来,就将手机号返回
        if not db_in_phone:
            return phone
import os
import decimal

import pytest
import requests
from common.excel_handler import ExcelHandler
from config.path import data_path
from common.yaml_handler import yaml_config, user_config
from common.logger_hander import logger
from common.helper import generate_new_phone
from common.db_handler import DBHandler

excel_file = os.path.join(data_path, 'demo.xlsx')
data = ExcelHandler(excel_file).read_dict('recharge')
print(data)
db = DBHandler()
sql = 'select leave_amount from member where id={}'.format(
    user_config['investor_user']['member_id'])
before_recharge_money = db.query(sql)


#db.db_colse()
@pytest.mark.parametrize('info', data)
def test_recharge(info, login):
    """充值"""
    """先要替换"""
    if "#member_id#" in info['json']:
        info["json"] = info["json"].replace('#member_id#', str(login['id']))
    if "#wrong_member_id#" in info['json']:
        info["json"] = info["json"].replace('#wrong_member_id#',
                                            str(login['id'] + 1))
Пример #6
0
import json
import os
import pytest
import requests
import decimal
from common.excel_handler import ExcelHandler
from config.path import data_path
from common.yaml_handler import yaml_config, user_config
from common.logger_hander import logger
from common.db_handler import DBHandler
from middleware.handler import Handler

excel_file = os.path.join(data_path, 'demo.xlsx')
data = ExcelHandler(excel_file).read_dict('withdraw')
db = DBHandler()
sql = 'select leave_amount from member where id={}'.format(
    user_config['investor_user']['member_id'])
before_recharge_money = db.query(sql)['leave_amount']


@pytest.mark.parametrize("info", data)
def test_withdraw(info, login):
    if "#member_id#" in info['json']:
        info["json"] = info["json"].replace("#member_id#", str(login['id']))
    if "#wrong_member_id#" in info['json']:
        info["json"] = info["json"].replace('#wrong_member_id#',
                                            str(login['id'] + 10))
    if "#amount#" in info["json"]:
        info["json"] = info["json"].replace('#amount#',
                                            str(before_recharge_money + 1))