Пример #1
0
def get_excel_interface_info(file_path):
    book = xlrd.open_workbook(file_path)
    interface_list = []
    # 拿到表格中对象 按索引获取
    sheet = book.sheet_by_index(0)
    for row in range(1, sheet.nrows):
        # 获取接口中的信息
        interface = {}
        random_obj = RandomData()
        interface['module'] = sheet.cell(row, 0).value
        interface['sub_module'] = sheet.cell(row, 1).value
        interface['case_name'] = sheet.cell(row, 2).value
        interface['interface_type'] = sheet.cell(row, 3).value
        interface['uri'] = sheet.cell(row, 4).value
        interface['send_method'] = sheet.cell(row, 5).value
        interface['body'] = json.loads(
            random_obj.random_data_format(sheet.cell(row, 6).value))
        interface['sql_path'] = sheet.cell(row, 7).value
        interface['conditions'] = json.loads(
            random_obj.get_random_data_value(sheet.cell(row, 8).value))
        interface['yml_path'] = sheet.cell(row, 9).value
        interface['expect_rst'] = random_obj.get_random_data_value(
            sheet.cell(row, 10).value)
        interface['setUp'] = sheet.cell(row, 11).value
        interface_list.append(interface)
    return interface_list
Пример #2
0
def submit_data_and_verify(username, pwd, uri, body, expected_rst, sql_path,
                           yml_path, send_method, **params):
    '''
    提交数据请求后,验证数据库结果
    :param expected_rst: 预期结果
    :param url: 请求url
    :param body: 请求报文
    :param sql_path: sql文件
    :param yml_path: yml格式化文件
    :param send_method: 请求方法
    :return:
    '''
    sql_file = sql_path
    yml_file = yml_path
    # 随机函数格式化body、conditions、expected_rst

    # 格式化前置条件传的数据
    setUp_dict = params['setUp']
    body = format_data_by_setup(body, setUp_dict)
    conditions = format_data_by_setup(params['query'], setUp_dict)
    expected_rst = format_data_by_setup(expected_rst, setUp_dict)

    random_obj = RandomData()
    expected_rst = random_obj.get_random_data_value(expected_rst)
    # 登录
    lg = Login(username, pwd)
    req = lg.req
    headers = {
        "Authorization": 'Bearer ' + lg.access_token,
        "k2": lg.defaultLoc,
        "k1": lg.defaultIns
    }
    # 发送接口请求
    url = URL_INFO['TEST']['url'] + uri
    if send_method == 'POST':
        rst = req.send_post(url, data=body, headers=headers)
    else:
        rst = req.send_get(url, data=body, headers=headers)
    # 数据库查询校验
    # 如果yml配置文件为空,则直接查询数据库,不需要进行格式化
    if yml_path == '':
        db_rst = query_db(sql_file, query=conditions)
        logger('数据库查询结果:').debug(db_rst)
        if len(db_rst) > 0:
            fm_db_rst = json.dumps(db_rst[0])
        else:
            logger('数据库查询结果:').error('数据库查询结果为空')
            fm_db_rst = '{}'
    else:
        fm_db_rst = get_db_format_data(sql_file, yml_file, query=conditions)
        logger('数据库查询结果根据YML格式化为:').debug(fm_db_rst)
    # 数据库查询结果和预期结果比对
    logger('【=====expected_rst预期结果为:=====】').debug(expected_rst)
    logger('【=====数据库需比对数据:=====】').debug(fm_db_rst)
    compare_data(expected_rst, fm_db_rst)
Пример #3
0
def get_excel_interface_data(file_path):
    '''
    获取接口的查询类型和提交类型的所有用例
    :param file_path:
    :return:
    '''
    book = xlrd.open_workbook(file_path)
    interface_list_queryType = []
    interface_list_submitType = []
    # 拿到表格中对象 按索引获取
    sheet = book.sheet_by_index(0)
    for row in range(1, sheet.nrows):
        if int(sheet.cell(row, 3).value) == 0:
            # 获取接口中的信息
            interface = {}
            random_obj = RandomData()
            interface['module'] = sheet.cell(row, 0).value
            interface['sub_module'] = sheet.cell(row, 1).value
            interface['case_name'] = sheet.cell(row, 2).value
            interface['interface_type'] = str(int(sheet.cell(row, 3).value))
            interface['uri'] = sheet.cell(row, 4).value
            interface['send_method'] = sheet.cell(row, 5).value
            interface['body'] = json.loads(
                random_obj.random_data_format(sheet.cell(row, 6).value))
            interface['sql_path'] = sheet.cell(row, 7).value
            interface['conditions'] = json.loads(
                random_obj.get_random_data_value(sheet.cell(row, 8).value))
            interface['yml_path'] = sheet.cell(row, 9).value
            interface['expected_rst'] = random_obj.get_random_data_value(
                sheet.cell(row, 10).value)
            interface['setUp'] = sheet.cell(row, 11).value
            interface_list_queryType.append(interface)
        elif int(sheet.cell(row, 3).value) == 1:
            interface = {}
            random_obj = RandomData()
            interface['module'] = sheet.cell(row, 0).value
            interface['sub_module'] = sheet.cell(row, 1).value
            interface['case_name'] = sheet.cell(row, 2).value
            interface['interface_type'] = str(int(sheet.cell(row, 3).value))
            interface['uri'] = sheet.cell(row, 4).value
            interface['send_method'] = sheet.cell(row, 5).value
            interface['body'] = json.loads(
                random_obj.random_data_format(sheet.cell(row, 6).value))
            interface['sql_path'] = sheet.cell(row, 7).value
            interface['conditions'] = json.loads(
                random_obj.get_random_data_value(sheet.cell(row, 8).value))
            interface['yml_path'] = sheet.cell(row, 9).value
            interface['expected_rst'] = random_obj.get_random_data_value(
                sheet.cell(row, 10).value)
            interface['setUp'] = sheet.cell(row, 11).value
            interface_list_submitType.append(interface)
    return interface_list_queryType, interface_list_submitType
Пример #4
0
def add_user_base_info():
    '''
    前置条件:新增个人档案
    :return:
    '''
    uri = '/app-publichealth/personal/addNewBaseInfo'
    randomData = RandomData()
    formJsonStr = '{\"liveAddress\":{\"city\":\"216449\",\"county\":\"218534\",\"province\":\"191019\",' \
                  '\"town\":\"218535\",\"village\":\"218536\",\"deep\":0,\"value\":\"218536\",\"label\":\"妙山社区\",' \
                  '\"code\":\"331023001040\",\"detailAddress\":\"现住址1\"},\"residenceAddress\":{\"city\":\"216449\",' \
                  '\"county\":\"218534\",\"province\":\"191019\",\"town\":\"218837\",\"village\":\"218844\",' \
                  '\"deep\":0,\"value\":\"218844\",\"label\":\"下洋潘村委会\",\"code\":\"331023105206\",' \
                  '\"detailAddress\":\"户籍地址1\"},\"mgrOrgCode\":\"1\",\"docOrgCode\":\"1\",\"inputOrgCode\":\"1\",' \
                  '\"inputOrgName\":\"浙江大学医学院附属第一医院\",\"responsibleDoctorId\":\"10165\",' \
                  '\"archivingDoctorId\":\"10165\",\"archivingDate\":\"faker.date()\",\"inputDoctorId\":\"10165\",' \
                  '\"inputDoctorName\":\"VV\",\"inputDate\":\"faker.date()\",\"nation\":\"GB/T3304.01\",' \
                  '\"gender\":\"GB/T2261.1.1\",\"isHouseholderReg\":\"1\",\"hasOperations\":[\"0\"],' \
                  '\"hasTraumatisms\":[\"0\"],\"hasTransfusions\":[\"0\"],\"allergySource\":[{\"value\":0,' \
                  '\"isReserveState\":true}],\"exposureHistory\":[{\"value\":0,\"isReserveState\":true}],' \
                  '\"diseases\":[{\"value\":\"FH0369.01\",\"isReserveState\":true,\"diagnosisTime\":\"\"}],' \
                  '\"fatherDiseases\":[{\"value\":\"FH0369.01\",\"isReserveState\":true}],\"motherDiseases\":[{' \
                  '\"value\":\"FH0369.01\",\"isReserveState\":true}],\"childrenDiseases\":[{\"value\":\"FH0369.01\",' \
                  '\"isReserveState\":true}],\"siblingDiseases\":[{\"value\":\"FH0369.01\",\"isReserveState\":true}],' \
                  '\"geneticDiseases\":[{\"value\":0,\"isReserveState\":true}],\"disabilityDiseases\":[{' \
                  '\"value\":\"FH0370.01\",\"isReserveState\":true}],\"lifeEnvKitchenVentList\":[{\"value\":0}],' \
                  '\"lifeEnvFuelTypeList\":[{\"value\":0}],\"lifeEnvWaterList\":[{\"value\":0}],\"lifeEnvWcList\":[{' \
                  '\"value\":0}],\"lifeEnvAnimalList\":[{\"value\":0}],\"gridId\":\"3310\",' \
                  '\"educationLevel\":\"FH0388.02\",\"aboBloodType\":\"CV04.50.005.01\",' \
                  '\"rhBloodType\":\"CV04.50.020.02\",\"maritalStatus\":\"GB/T2261.2.10\",' \
                  '\"careerCate\":\"FH0386.05\",\"hisPayFeeType\":\"FH0368.02\",\"recordDetailCategory\":\"addNew\",' \
                  '\"name\":\"faker.name()\",\"birthday\":\"1990-03-07\",\"idcardNumber\":\"faker.ssn()\",' \
                  '\"phone\":\"faker.phone_number()\",\"workplace\":\"工作单位1\",\"contactsName\":\"faker.name()\",' \
                  '\"contactsPhone\":\"faker.phone_number()\",\"idcardType\":\"FH0066.01\",\"qcResult\":[]} '
    formJsonStr = randomData.random_data_format(formJsonStr)
    body = {"formJsonStr": formJsonStr}
    request_api(USER_INFO['xtest01']['username'],
                USER_INFO['xtest01']['password'], uri, body)
    return randomData.interface_case_globals
Пример #5
0
def get_excel_scene_data(file_path):
    '''
    获取场景类型的执行用例
    :param file_path:
    :return:
    '''
    scene_all = {}
    book = xlrd.open_workbook(file_path)

    # 拿到表格中对象 按索引获取
    sheet = book.sheet_by_index(0)
    file_obj = 0
    # 获取所有场景数据
    scene_dict = {}
    for row in range(1, sheet.nrows):
        scene_name = sheet.cell(row, 2).value

        if scene_name not in scene_all.keys():
            scene = []
            if not scene:
                random_obj = RandomData()
                interface_dict = {}
                # 获取接口中的信息
                interface_dict['module'] = sheet.cell(row, 0).value
                interface_dict['sub_module'] = sheet.cell(row, 1).value
                interface_dict['scene_name'] = sheet.cell(row, 2).value
                interface_dict['interface_name'] = sheet.cell(row, 3).value
                interface_dict['interface_type'] = sheet.cell(row, 4).value
                interface_dict['uri'] = sheet.cell(row, 5).value
                interface_dict['send_method'] = sheet.cell(row, 6).value
                interface_dict['body'] = random_obj.random_data_format(
                    sheet.cell(row, 7).value)
                interface_dict['rely'] = sheet.cell(row, 8).value
                interface_dict['sql'] = sheet.cell(row, 9).value
                interface_dict['condition'] = random_obj.get_random_data_value(
                    sheet.cell(row, 10).value)
                interface_dict['yml'] = sheet.cell(row, 11).value
                interface_dict[
                    'expected_rst'] = random_obj.get_random_data_value(
                        sheet.cell(row, 12).value)
                interface_dict['setUp'] = sheet.cell(row, 13).value
                scene.append(interface_dict)
                scene_dict[scene_name] = scene
                scene_all[scene_name] = scene
        else:
            random_obj = RandomData()
            interface_dict = {}
            # 获取接口中的信息
            interface_dict['module'] = sheet.cell(row, 0).value
            interface_dict['sub_module'] = sheet.cell(row, 1).value
            interface_dict['scene_name'] = sheet.cell(row, 2).value
            interface_dict['interface_name'] = sheet.cell(row, 3).value
            interface_dict['interface_type'] = sheet.cell(row, 4).value
            interface_dict['uri'] = sheet.cell(row, 5).value
            interface_dict['send_method'] = sheet.cell(row, 6).value
            interface_dict['body'] = random_obj.random_data_format(
                sheet.cell(row, 7).value)
            interface_dict['rely'] = sheet.cell(row, 8).value
            interface_dict['sql'] = sheet.cell(row, 9).value
            interface_dict['condition'] = sheet.cell(row, 10).value
            interface_dict['yml'] = sheet.cell(row, 11).value
            interface_dict['expected_rst'] = sheet.cell(row, 12).value
            interface_dict['setUp'] = sheet.cell(row, 13).value
            scene_dict[scene_name] = scene
            scene_all[scene_name].append(interface_dict)
    # 根据场景生成自动化测试脚本
    return scene_all.values()